﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Diagnostics;
using System.IO;
using System.Text;
using PSE.Deployment.SetupBase.Configuration;
using PSE.Deployment.SetupBase.Configuration.Actions;
using PSE.Deployment.SetupBase.Configuration.Enums;
using PSE.Deployment.SetupBase.Parameter.Enums;
using Sinacor.Deployment.Setup.Configuration;
using PSE.Deployment.Util;

namespace Sinacor.Deployment.SinacorSetupGenerator
{
    public class Program
    {
        private static SinacorConfiguration config;
        private static Group _groupDependencyFwkSinacorCore;
        private static Group _groupDependencyFwkSinacorClient;
        private static Group _groupDependencyFwkSinacorServer;

        private static Group _groupDependencyPmSinacorClient;
        private static Group _groupDependencyPmSinacorServer;
        private static Group _groupDependencyComSinacor;

        private static DataBaseScripts DataBaseScripts;
        private static string _outPutPath;
        private static SystemInfo _systemInfo;
        private static bool _generateDataBaseInfo = true;

        private static string _connectionString;

        public static void Main(string[] args)
        {
            try
            {
                _systemInfo = new SystemInfo();
                _systemInfo.Id = "Sinacor";
                _systemInfo.Description = "Sistema de administração de corretoras";

                if (args.Length == 0)
                {
                    if (Debugger.IsAttached)
                    {
                        _systemInfo.Version = new PSE.Framework.Common.Version(1, 10, 0, 0);
                        _outPutPath = @"C:\DSEPROJ\Compilados\Sinacor\Deployment\";
                    }
                    else
                    {
                        throw new Exception("Invalid arguments!");
                    }
                }
                else if (args.Length == 2)
                {
                    _systemInfo.Version = new PSE.Framework.Common.Version(args[0]);
                    _outPutPath = args[1];
                }
                else if (args.Length == 3)
                {
                    _systemInfo.Version = new PSE.Framework.Common.Version(args[0]);
                    _outPutPath = args[1];
                    Boolean.TryParse(args[2], out _generateDataBaseInfo);
                }
                else
                {
                    throw new Exception("Invalid arguments!");
                }

                _connectionString = System.Configuration.ConfigurationManager.AppSettings["ProcessManagerConnectionString"];

                PopulateConfig();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
            }
        }

        private static void PopulateConfig()
        {
            config = new SinacorConfiguration();

            config.SystemInfo = _systemInfo.Clone();

            config.DefaultInstallPath = @"BMFBOVESPA\";

            PopulateDependencies();

            PopulateInterfaceLayer(config);

            PopulateProcessManager(config);

            PopulateServiceLayer(config);

            if (_generateDataBaseInfo)
            {
                PopulateDataBase();
            }

            //PopulateMSMQ();

            PopulateDataBaseScript();

            PSE.Deployment.Util.Serializer.Serialize<SinacorConfiguration>(config, Path.Combine(_outPutPath, "SetupConfiguration.xml"));
            PSE.Deployment.Util.Serializer.Serialize<DataBaseScripts>(DataBaseScripts, Path.Combine(_outPutPath, "DataBaseScripts.xml"));

            //Sinacor.Deployment.Setup.Parameter.SinacorParameter p = new Sinacor.Deployment.Setup.Parameter.SinacorParameter();
            //p.SetupConfiguration = (SinacorConfiguration)PSE.Deployment.Util.CloneHelper.Clone(config);
            //p.SetupConfiguration = PSE.Deployment.Util.Serializer.Deserialize<SinacorConfiguration>(Path.Combine(_outPutPath, "SetupConfiguration.xml"));
            //p.Prerequisites.DataBase = PrerequisitesStatus.Ok;
            //p.DataBase.ConnectionInfo = new Sinacor.Deployment.Setup.Parameter.DataBaseConnection();
            //p.DataBase.ConnectionInfo.User = "SINAMAIS";
            //p.DataBase.ConnectionInfo.Password = PSE.Deployment.Util.EncryptDecrypt.Encrypt("SINAWIN");
            //p.DataBase.ConnectionInfo.TNSName = "SINADES";
            //p.InstalationSource = _outPutPath;
            //p.InstallationPath = @"C:\DSEPROJ\Compilados\"; //Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\" + p.SetupConfiguration.DefaultInstallPath;
            //p.SetupConfiguration.SystemInfo.Groups.SelectDeep(g => g.SubGroups).SelectDeep(g => g.Dependencies).ToList().ForEach(g => { g.Install = true; g.Installed = true; });
            //PSE.Deployment.Util.Serializer.Serialize<Sinacor.Deployment.Setup.Parameter.SinacorParameter>(p, @"C:\Documents and Settings\All Users\Application Data\BMFBOVESPA\Sinacor\SinacorParameters_v1.xml");
        }

        private static void PopulateInterfaceLayer(SinacorConfiguration config)
        {
            Group groupInterface = new Group();
            groupInterface.System = _systemInfo.Clone();
            groupInterface.Id = "InterfaceLayer";
            groupInterface.Name = "Interface Gráfica";
            groupInterface.Description = "Camada de Interface Gráfica";
            groupInterface.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            groupInterface.Module.Id = "INFRA";
            groupInterface.Module.Name = "Componentes do Framework";
            groupInterface.Index = 0;
            AddActionCopy(groupInterface, "Copia dos arquivos da aplicação", @"UI\Application\Help\", @"UI\Application\Languages\", @"UI\Application\Themes\");

            object[][] shortCuts = new object[][]
            {
                new object[] { @"UI\Application\", "Sinacor.exe", @"UI\Application\", "Sinacor.ico", @"Sinacor\", "Sinacor.lnk" ,  new List<PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder>() { PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder.Desktop, PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder.StartMenu } },
                new object[] { @"UI\Application\", "LogPackager.exe", @"UI\Application\", "LogPackager.ico", @"Sinacor\", "Coletor de Evidências.lnk" , new List<PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder>() { PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder.StartMenu  } }
            };

            AddCreateShortcut(groupInterface, "Criação dos atalhos", shortCuts);

            AddActionUpdateConfigInterfaceLayer(groupInterface);

            ((Copy)(groupInterface.Actions[0])).Folders.Insert(0, new FolderInfo()
            {
                Source = @"Bin\Sinacor\UI\Application\",
                Destination = @"Sinacor\UI\Application\",
                Files = new List<string>() { 
                    "Sinacor.UI.Application.Menu.Communication.dll", 
                    "Sinacor.UI.Application.Menu.Model.dll", 
                    "Sinacor.UI.Application.Menu.Presenter.dll",
                    "Sinacor.UI.Application.Menu.View.SmartClient.dll",
                    "Sinacor.UI.Application.Settings.dll",
                    "Sinacor.UI.HelpViewer.Service.dll",
                    "Sinacor.UI.HelpViewer.View.dll",
                    "Sinacor.exe",
                    "Sinacor.ico",                     
                    "SinacorHelp.exe",
                    "LogPackager.exe",
                    "LogPackager.ico",
                    "Sinacor.exe.config",                    
                    "SinacorHelp.exe.config",
                    "LogPackager.exe.config"
                },
            });

            //Group groupInterfaceBMF = new Group();
            //groupInterfaceBMF.System = _systemInfo.Clone();
            //groupInterfaceBMF.Id = "InterfaceLayer-BMF";
            //groupInterfaceBMF.Name = "Controle de Ordens BMF";
            //groupInterfaceBMF.Description = "Interfaces do módulo Controle de Ordens BMF";
            //groupInterfaceBMF.Module.Id = "OMF";
            //groupInterfaceBMF.Module.Name = "Controle de Ordens BMF";
            //groupInterfaceBMF.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            //groupInterfaceBMF.Index = 0;
            //groupInterfaceBMF.AddDependency(_groupDependencyFwkSinacorClient);
            //groupInterfaceBMF.AddDependency(_groupDependencyPmSinacorClient);
            //groupInterface.AddSubGroup(groupInterfaceBMF);
            //AddActionCopy(groupInterfaceBMF, "Copia dos arquivos do módulo Controle de Ordens BMF", @"UI\Application\Bmf\");

            Group groupInterfaceBmf = new Group();
            groupInterfaceBmf.System = _systemInfo.Clone();
            groupInterfaceBmf.Id = "InterfaceLayer-Bmf";
            groupInterfaceBmf.Name = "Bmf";
            groupInterfaceBmf.Description = "Interfaces do módulo BM&F";
            groupInterfaceBmf.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            groupInterfaceBmf.Index = 0;

            Group groupInterfaceBmfOrdens = new Group();
            groupInterfaceBmfOrdens.System = _systemInfo.Clone();
            groupInterfaceBmfOrdens.Id = "InterfaceLayer-BMF-Ordens";
            groupInterfaceBmfOrdens.Name = "Controle de Ordens BM&F";
            groupInterfaceBmfOrdens.Description = "Interfaces do módulo Controle de Ordens BM&F";
            groupInterfaceBmfOrdens.Module.Id = "OMF";
            groupInterfaceBmfOrdens.Module.Name = "Controle de Ordens BM&F";
            groupInterfaceBmfOrdens.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            groupInterfaceBmfOrdens.Index = 0;
            groupInterfaceBmfOrdens.AddDependency(_groupDependencyFwkSinacorClient);
            groupInterfaceBmfOrdens.AddDependency(_groupDependencyPmSinacorClient);
            groupInterfaceBmf.AddSubGroup(groupInterfaceBmfOrdens);
            AddActionCopy(groupInterfaceBmfOrdens, "Copia dos arquivos do módulo Controle de Ordens BM&F", @"UI\Application\Bmf\");

            Group groupInterfaceBmfFaturamento = new Group();
            groupInterfaceBmfFaturamento.System = _systemInfo.Clone();
            groupInterfaceBmfFaturamento.Id = "InterfaceLayer-BMF-Faturamento";
            groupInterfaceBmfFaturamento.Name = "Faturamento BM&F";
            groupInterfaceBmfFaturamento.Description = "Interfaces do módulo Faturamento BM&F";
            groupInterfaceBmfFaturamento.Module.Id = "BMF";
            groupInterfaceBmfFaturamento.Module.Name = "Faturamento BM&F";
            groupInterfaceBmfFaturamento.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            groupInterfaceBmfFaturamento.Index = 1;
            groupInterfaceBmfFaturamento.AddDependency(_groupDependencyFwkSinacorClient);
            groupInterfaceBmfFaturamento.AddDependency(_groupDependencyPmSinacorClient);
            groupInterfaceBmf.AddSubGroup(groupInterfaceBmfFaturamento);
            AddActionCopy(groupInterfaceBmfFaturamento, "Copia dos arquivos do módulo Faturamento BM&F", @"UI\Application\Bmf\");

            groupInterface.AddSubGroup(groupInterfaceBmf);

            Group groupInterfaceBovespa = new Group();
            groupInterfaceBovespa.System = _systemInfo.Clone();
            groupInterfaceBovespa.Id = "InterfaceLayer-Bovespa";
            groupInterfaceBovespa.Name = "Bovespa";
            groupInterfaceBovespa.Description = "Interfaces do módulo Bovespa";
            groupInterfaceBovespa.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            groupInterfaceBovespa.Index = 1;

            Group groupInterfaceBovespaOrdens = new Group();
            groupInterfaceBovespaOrdens.System = _systemInfo.Clone();
            groupInterfaceBovespaOrdens.Id = "InterfaceLayer-Bovespa-Ordens";
            groupInterfaceBovespaOrdens.Name = "Controle de Ordens Bovespa";
            groupInterfaceBovespaOrdens.Description = "Interfaces do módulo Controle de Ordens Bovespa";
            groupInterfaceBovespaOrdens.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            groupInterfaceBovespaOrdens.Module.Id = "ORD";
            groupInterfaceBovespaOrdens.Module.Name = "Controle de Ordens Bovespa";
            groupInterfaceBovespaOrdens.Index = 0;
            groupInterfaceBovespaOrdens.AddDependency(_groupDependencyFwkSinacorClient);
            groupInterfaceBovespaOrdens.AddDependency(_groupDependencyPmSinacorClient);
            groupInterfaceBovespa.AddSubGroup(groupInterfaceBovespaOrdens);
            AddActionCopy(groupInterfaceBovespaOrdens, "Copia dos arquivos do módulo Controle de Ordens Bovespa", @"UI\Application\Bovespa\");

            Group groupInterfaceBovespaFaturamento = new Group();
            groupInterfaceBovespaFaturamento.System = _systemInfo.Clone();
            groupInterfaceBovespaFaturamento.Id = "InterfaceLayer-Bovespa-Faturamento";
            groupInterfaceBovespaFaturamento.Name = "Faturamento Bovespa";
            groupInterfaceBovespaFaturamento.Description = "Interfaces do módulo Faturamento Bovespa";
            groupInterfaceBovespaFaturamento.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            groupInterfaceBovespaFaturamento.Module.Id = "BOL";
            groupInterfaceBovespaFaturamento.Module.Name = "Faturamento Bovespa";
            groupInterfaceBovespaFaturamento.Index = 1;
            groupInterfaceBovespaFaturamento.AddDependency(_groupDependencyFwkSinacorClient);
            groupInterfaceBovespaFaturamento.AddDependency(_groupDependencyPmSinacorClient);
            groupInterfaceBovespa.AddSubGroup(groupInterfaceBovespaFaturamento);
            AddActionCopy(groupInterfaceBovespaFaturamento, "Copia dos arquivos do módulo Faturamento Bovespa", @"UI\Application\Bovespa\");

            groupInterface.AddSubGroup(groupInterfaceBovespa);

            Group groupInterfaceClientes = new Group();
            groupInterfaceClientes.System = _systemInfo.Clone();
            groupInterfaceClientes.Id = "InterfaceLayer-Clientes";
            groupInterfaceClientes.Name = "Clientes";
            groupInterfaceClientes.Description = "Interfaces do módulo Clientes";
            groupInterfaceClientes.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            groupInterfaceClientes.Module.Id = "CLI";
            groupInterfaceClientes.Module.Name = "Clientes";
            groupInterfaceClientes.Index = 2;
            groupInterfaceClientes.AddDependency(_groupDependencyFwkSinacorClient);
            groupInterfaceClientes.AddDependency(_groupDependencyPmSinacorClient);
            groupInterface.AddSubGroup(groupInterfaceClientes);
            AddActionCopy(groupInterfaceClientes, "Copia dos arquivos do módulo Clientes", @"UI\Application\Clientes\", @"UI\Application\InformacaoApoio\");

            Group groupInterfaceContasCorrentes = new Group();
            groupInterfaceContasCorrentes.System = _systemInfo.Clone();
            groupInterfaceContasCorrentes.Id = "InterfaceLayer-ContasCorrentes";
            groupInterfaceContasCorrentes.Name = "Contas Correntes";
            groupInterfaceContasCorrentes.Description = "Interfaces do módulo Contas Correntes";
            groupInterfaceContasCorrentes.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            groupInterfaceContasCorrentes.Module.Id = "CCO";
            groupInterfaceContasCorrentes.Module.Name = "Contas Correntes";
            groupInterfaceContasCorrentes.Index = 3;
            groupInterfaceContasCorrentes.AddDependency(_groupDependencyFwkSinacorClient);
            groupInterfaceContasCorrentes.AddDependency(_groupDependencyPmSinacorClient);
            groupInterface.AddSubGroup(groupInterfaceContasCorrentes);
            AddActionCopy(groupInterfaceContasCorrentes, "Copia dos arquivos do módulo Contas Correntes", @"UI\Application\ContaCorrente\");

            Group groupInterfaceTesouraria = new Group();
            groupInterfaceTesouraria.System = _systemInfo.Clone();
            groupInterfaceTesouraria.Id = "InterfaceLayer-Tesouraria";
            groupInterfaceTesouraria.Name = "Tesouraria";
            groupInterfaceTesouraria.Description = "Interfaces do módulo Tesouraria";
            groupInterfaceTesouraria.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            groupInterfaceTesouraria.Module.Id = "TES";
            groupInterfaceTesouraria.Module.Name = "Tesouraria";
            groupInterfaceTesouraria.Index = 4;
            groupInterfaceTesouraria.AddDependency(_groupDependencyFwkSinacorClient);
            groupInterfaceTesouraria.AddDependency(_groupDependencyPmSinacorClient);
            groupInterface.AddSubGroup(groupInterfaceTesouraria);
            AddActionCopy(groupInterfaceTesouraria, "Copia dos arquivos do módulo Tesouraria", @"UI\Application\Tesouraria\", @"UI\Application\Solicitacoes\");

            Group groupInterfaceContasPagar = new Group();
            groupInterfaceContasPagar.System = _systemInfo.Clone();
            groupInterfaceContasPagar.Id = "InterfaceLayer-ContasPagar";
            groupInterfaceContasPagar.Name = "Contas a Pagar";
            groupInterfaceContasPagar.Description = "Interfaces do módulo ContasPagar";
            groupInterfaceContasPagar.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            groupInterfaceContasPagar.Module.Id = "CTP";
            groupInterfaceContasPagar.Module.Name = "Contas a Pagar";
            groupInterfaceContasPagar.Index = 5;
            groupInterfaceContasPagar.AddDependency(_groupDependencyFwkSinacorClient);
            groupInterfaceContasPagar.AddDependency(_groupDependencyPmSinacorClient);
            groupInterface.AddSubGroup(groupInterfaceContasPagar);
            AddActionCopy(groupInterfaceContasPagar, "Copia dos arquivos do módulo ContasPagar", @"UI\Application\ContasPagar\");

            config.SystemInfo.Groups.Add(groupInterface);
        }

        private static void PopulateServiceLayer(SinacorConfiguration config)
        {
            Group groupService = new Group();
            groupService.System = _systemInfo.Clone();
            groupService.Id = "ServiceLayer";
            groupService.Name = "Serviços";
            groupService.Description = "Camada de Serviços";
            groupService.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupService.Module.Id = "INFRA";
            groupService.Module.Name = "Componentes do Framework";
            groupService.Index = 2;
            //AddActionInstallWcfServiceMain(groupService, "Instalação do site principal do sistema");

            Group groupServiceAutenticacao = new Group();
            groupServiceAutenticacao.System = _systemInfo.Clone();
            groupServiceAutenticacao.Id = "ServiceLayer-Autenticacao";
            groupServiceAutenticacao.Name = "Autenticação";
            groupServiceAutenticacao.Description = "Serviços de Autenticação";
            groupServiceAutenticacao.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupServiceAutenticacao.Module.Id = "INFRA";
            groupServiceAutenticacao.Module.Name = "Componentes do Framework";
            groupServiceAutenticacao.Index = 0;
            groupServiceAutenticacao.AddDependency(_groupDependencyFwkSinacorServer);
            groupService.AddSubGroup(groupServiceAutenticacao);
            AddActionCopy(groupServiceAutenticacao, "Copia dos arquivos do módulo de Autenticação", @"Servicos\Infra Services\");
            AddActionInstallWcfService(groupServiceAutenticacao, "Infra", "/Sinacor/Infra", "Instalação dos serviços do módulo de Autenticação", @"Servicos\Infra Services\");
            AddActionInstallWindowsService(groupServiceAutenticacao, "Instalação do serviço de STS do Sinacor",
                new string[] { "STS Hoster Service", "STS Hoster Service", "Instalação do serviço de STS do Sinacor", @"Servicos\Infra Services\STS Hoster\", @"STSHosterService.exe", @"STSHosterService.exe.config", "true" });

            //Group groupServiceLog = new Group();
            //groupServiceLog.System = _systemInfo.Clone();
            //groupServiceLog.Id = "ServiceLayer-Log";
            //groupServiceLog.Name = "Log";
            //groupServiceLog.Description = "Serviços de Log";
            //groupServiceLog.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            //groupServiceLog.Module.Id = "INFRA";
            //groupServiceLog.Module.Name = "Componentes do Framework";
            //groupServiceLog.Index = 1;
            //groupServiceLog.AddDependency(_groupDependencyFwkSinacorServer);
            //groupService.AddSubGroup(groupServiceLog);
            //AddActionCopy(groupServiceLog, "Copia dos arquivos do serviço de Log", @"Core\Logging Service\");
            //AddActionInstallWindowsService(groupServiceLog, "Instalação do serviço do Log do Sinacor",
            //    new string[] { "SinacorLoggingService", "Sinacor Logging Service", "Instalação do serviço do Log do Sinacor", @"Core\Logging Service\", @"Sinacor.Infra.Core.Logging.ServiceLogging.exe", @"Sinacor.Infra.Core.Logging.ServiceLogging.exe.config", "true" });

            //Group groupServiceBMF = new Group();
            //groupServiceBMF.System = _systemInfo.Clone();
            //groupServiceBMF.Id = "ServiceLayer-BMF";
            //groupServiceBMF.Name = "Controle de Ordens BMF";
            //groupServiceBMF.Description = "Serviços do módulo Controle de Ordens BMF";
            //groupServiceBMF.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            //groupServiceBMF.Module.Id = "OMF";
            //groupServiceBMF.Module.Name = "Controle de Ordens BMF";
            //groupServiceBMF.Index = 2;
            //groupServiceBMF.AddDependency(_groupDependencyFwkSinacorServer);
            //groupService.AddSubGroup(groupServiceBMF);
            //AddActionCopy(groupServiceBMF, "Copia dos arquivos do módulo Controle de Ordens BMF", @"Servicos\Bmf\");
            //AddActionInstallWcfService(groupServiceBMF, "BMF", "Instalação dos serviços do módulo Controle de Ordens BMF", @"Servicos\Bmf\");

            Group groupServiceBmf = new Group();
            groupServiceBmf.System = _systemInfo.Clone();
            groupServiceBmf.Id = "ServiceLayer-Bmf";
            groupServiceBmf.Name = "Bmf";
            groupServiceBmf.Description = "Serviços do módulo BM&F";
            groupServiceBmf.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupServiceBmf.Index = 2;

            Group groupServiceBmfOrdens = new Group();
            groupServiceBmfOrdens.System = _systemInfo.Clone();
            groupServiceBmfOrdens.Id = "ServiceLayer-BMF-Ordens";
            groupServiceBmfOrdens.Name = "Controle de Ordens BM&F";
            groupServiceBmfOrdens.Description = "Serviços do módulo Controle de Ordens BM&F";
            groupServiceBmfOrdens.Module.Id = "OMF";
            groupServiceBmfOrdens.Module.Name = "Controle de Ordens BM&F";
            groupServiceBmfOrdens.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupServiceBmfOrdens.Index = 0;
            groupServiceBmfOrdens.AddDependency(_groupDependencyFwkSinacorServer);
            groupServiceBmf.AddSubGroup(groupServiceBmfOrdens);
            AddActionCopy(groupServiceBmfOrdens, "Copia dos arquivos do módulo Controle de Ordens BM&F", @"Servicos\Bmf\");
            AddActionInstallWcfService(groupServiceBmfOrdens, "BMF", "/Sinacor/BMF", "Instalação dos serviços do módulo Controle de Ordens BM&F", @"Servicos\Bmf\");

            Group groupServiceBmfFaturamento = new Group();
            groupServiceBmfFaturamento.System = _systemInfo.Clone();
            groupServiceBmfFaturamento.Id = "ServiceLayer-BMF-Faturamento";
            groupServiceBmfFaturamento.Name = "Faturamento BM&F";
            groupServiceBmfFaturamento.Description = "Serviços do módulo Faturamento BM&F";
            groupServiceBmfFaturamento.Module.Id = "BMF";
            groupServiceBmfFaturamento.Module.Name = "Faturamento BM&F";
            groupServiceBmfFaturamento.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupServiceBmfFaturamento.Index = 1;
            groupServiceBmfFaturamento.AddDependency(_groupDependencyFwkSinacorServer);
            groupServiceBmf.AddSubGroup(groupServiceBmfFaturamento);
            AddActionCopy(groupServiceBmfFaturamento, "Copia dos arquivos do módulo Faturamento BM&F", @"Servicos\Bmf\");
            AddActionInstallWcfService(groupServiceBmfFaturamento, "BMF", "/Sinacor/BMF", "Instalação dos serviços do módulo Faturamento BM&F", @"Servicos\Bmf\");

            groupService.AddSubGroup(groupServiceBmf);

            Group groupServiceBovespa = new Group();
            groupServiceBovespa.System = _systemInfo.Clone();
            groupServiceBovespa.Id = "ServiceLayer-Bovespa";
            groupServiceBovespa.Name = "Bovespa";
            groupServiceBovespa.Description = "Serviços do módulo Bovespa";
            groupServiceBovespa.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupServiceBovespa.Index = 3;

            Group groupServiceBovespaOrdens = new Group();
            groupServiceBovespaOrdens.System = _systemInfo.Clone();
            groupServiceBovespaOrdens.Id = "ServiceLayer-Bovespa-Ordens";
            groupServiceBovespaOrdens.Name = "Controle de Ordens Bovespa";
            groupServiceBovespaOrdens.Description = "Serviços do módulo Controle de Ordens Bovespa";
            groupServiceBovespaOrdens.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupServiceBovespaOrdens.Module.Id = "ORD";
            groupServiceBovespaOrdens.Module.Name = "Controle de Ordens Bovespa";
            groupServiceBovespaOrdens.Index = 0;
            groupServiceBovespaOrdens.AddDependency(_groupDependencyFwkSinacorServer);
            groupServiceBovespa.AddSubGroup(groupServiceBovespaOrdens);
            AddActionCopy(groupServiceBovespaOrdens, "Copia dos arquivos do módulo Controle de Ordens Bovespa", @"Servicos\Bovespa\");
            AddActionInstallWcfService(groupServiceBovespaOrdens, "Bovespa", "/Sinacor/Bovespa", "Instalação dos serviços do módulo Controle de Ordens Bovespa", @"Servicos\Bovespa\");

            Group groupServiceBovespaFaturamento = new Group();
            groupServiceBovespaFaturamento.System = _systemInfo.Clone();
            groupServiceBovespaFaturamento.Id = "ServiceLayer-Bovespa-Faturamento";
            groupServiceBovespaFaturamento.Name = "Faturamento Bovespa";
            groupServiceBovespaFaturamento.Description = "Serviços do módulo Faturamento Bovespa";
            groupServiceBovespaFaturamento.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupServiceBovespaFaturamento.Module.Id = "BOL";
            groupServiceBovespaFaturamento.Module.Name = "Faturamento Bovespa";
            groupServiceBovespaFaturamento.Index = 1;
            groupServiceBovespaFaturamento.AddDependency(_groupDependencyFwkSinacorServer);
            groupServiceBovespa.AddSubGroup(groupServiceBovespaFaturamento);
            AddActionCopy(groupServiceBovespaFaturamento, "Copia dos arquivos do módulo Faturamento Bovespa", @"Servicos\Bovespa\");
            AddActionInstallWcfService(groupServiceBovespaFaturamento, "Bovespa", "/Sinacor/Bovespa", "Instalação dos serviços do módulo Faturamento Bovespa", @"Servicos\Bovespa\");

            groupService.AddSubGroup(groupServiceBovespa);

            Group groupServiceClientes = new Group();
            groupServiceClientes.System = _systemInfo.Clone();
            groupServiceClientes.Id = "ServiceLayer-Clientes";
            groupServiceClientes.Name = "Clientes";
            groupServiceClientes.Description = "Serviços do módulo Clientes";
            groupServiceClientes.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupServiceClientes.Module.Id = "CLI";
            groupServiceClientes.Module.Name = "Clientes";
            groupServiceClientes.Index = 4;
            groupServiceClientes.AddDependency(_groupDependencyFwkSinacorServer);
            groupService.AddSubGroup(groupServiceClientes);
            AddActionCopy(groupServiceClientes, "Copia dos arquivos do módulo Clientes", @"Servicos\Clientes\");
            AddActionInstallWcfService(groupServiceClientes, "Clientes", "/Sinacor/Clientes", "Instalação dos serviços do módulo Clientes", @"Servicos\Clientes\");

            Group groupServiceInformacaoApoio = new Group();
            groupServiceInformacaoApoio.System = _systemInfo.Clone();
            groupServiceInformacaoApoio.Id = "ServiceLayer-InformacaoApoio";
            groupServiceInformacaoApoio.Name = "Informações de Apoio";
            groupServiceInformacaoApoio.Description = "Serviços do módulo Informações de Apoio";
            groupServiceInformacaoApoio.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupServiceInformacaoApoio.Module.Id = "IAPO";
            groupServiceInformacaoApoio.Module.Name = "Informações de Apoio";
            groupServiceInformacaoApoio.Index = 5;
            groupServiceInformacaoApoio.AddDependency(_groupDependencyFwkSinacorServer);
            groupService.AddSubGroup(groupServiceInformacaoApoio);
            AddActionCopy(groupServiceInformacaoApoio, "Copia dos arquivos do módulo Informações de Apoio", @"Servicos\InformacaoApoio\");
            AddActionInstallWcfService(groupServiceInformacaoApoio, "InformacaoApoio", "/Sinacor/InformacaoApoio", "Instalação dos serviços do módulo Informações de Apoio", @"Servicos\InformacaoApoio\");

            Group groupServiceContasCorrentes = new Group();
            groupServiceContasCorrentes.System = _systemInfo.Clone();
            groupServiceContasCorrentes.Id = "ServiceLayer-ContasCorrentes";
            groupServiceContasCorrentes.Name = "Contas Correntes";
            groupServiceContasCorrentes.Description = "Serviços do módulo Contas Correntes";
            groupServiceContasCorrentes.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupServiceContasCorrentes.Module.Id = "CCO";
            groupServiceContasCorrentes.Module.Name = "Contas Correntes";
            groupServiceContasCorrentes.Index = 6;
            groupServiceContasCorrentes.AddDependency(_groupDependencyFwkSinacorServer);
            groupService.AddSubGroup(groupServiceContasCorrentes);
            AddActionCopy(groupServiceContasCorrentes, "Copia dos arquivos do módulo Contas Correntes", @"Servicos\ContaCorrente\");
            AddActionInstallWcfService(groupServiceContasCorrentes, "ContaCorrente", "/Sinacor/ContaCorrente", "Instalação dos serviços do módulo Contas Correntes", @"Servicos\ContaCorrente\");

            Group groupServiceTesouraria = new Group();
            groupServiceTesouraria.System = _systemInfo.Clone();
            groupServiceTesouraria.Id = "ServiceLayer-Tesouraria";
            groupServiceTesouraria.Name = "Tesouraria";
            groupServiceTesouraria.Description = "Serviços do módulo Tesouraria";
            groupServiceTesouraria.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupServiceTesouraria.Module.Id = "TES";
            groupServiceTesouraria.Module.Name = "Tesouraria";
            groupServiceTesouraria.Index = 7;
            groupServiceTesouraria.AddDependency(_groupDependencyFwkSinacorServer);
            groupService.AddSubGroup(groupServiceTesouraria);
            AddActionCopy(groupServiceTesouraria, "Copia dos arquivos do módulo Tesouraria", @"Servicos\Tesouraria\", @"Servicos\Solicitacoes\");
            AddActionInstallWcfService(groupServiceTesouraria, "Tesouraria", "/Sinacor/Tesouraria", "Instalação dos serviços do módulo Tesouraria", @"Servicos\Tesouraria\", @"Servicos\Solicitacoes\");

            Group groupServiceContasPagar = new Group();
            groupServiceContasPagar.System = _systemInfo.Clone();
            groupServiceContasPagar.Id = "ServiceLayer-ContasPagar";
            groupServiceContasPagar.Name = "Contas a Pagar";
            groupServiceContasPagar.Description = "Serviços do módulo ContasPagar";
            groupServiceContasPagar.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupServiceContasPagar.Module.Id = "CTP";
            groupServiceContasPagar.Module.Name = "Contas a Pagar";
            groupServiceContasPagar.Index = 8;
            groupServiceContasPagar.AddDependency(_groupDependencyFwkSinacorServer);
            groupService.AddSubGroup(groupServiceContasPagar);
            AddActionCopy(groupServiceContasPagar, "Copia dos arquivos do módulo Contas a Pagar", @"Servicos\ContasPagar\");
            AddActionInstallWcfService(groupServiceContasPagar, "ContasPagar", "/Sinacor/ContasPagar", "Instalação dos serviços do módulo ContasPagar", @"Servicos\ContasPagar\");

            config.SystemInfo.Groups.Add(groupService);
        }

        private static void PopulateProcessManager(SinacorConfiguration config)
        {
            Group groupGP = new Group();
            groupGP.System = _systemInfo.Clone();
            groupGP.Id = "ProcessManager";
            groupGP.Name = "Gerenciador de Processos";
            groupGP.Description = "Camada do Gerenciador de Processos";
            groupGP.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupGP.Module.Id = "INFRA";
            groupGP.Module.Name = "Componentes do Framework";
            groupGP.Index = 1;
            groupGP.SubGroups = new List<Group>();
            AddActionInstallProcessManagerProduct(groupGP, "Instalação do produto Sinacor no Process Manager");
            //AddActionUpdateConfigProcessManagerGeneral(groupGP);

            //Group groupGPBMF = new Group();
            //groupGPBMF.System = _systemInfo.Clone();
            //groupGPBMF.Id = "ProcessManager-BMF";
            //groupGPBMF.Name = "Controle de Ordens BMF";
            //groupGPBMF.Description = "Processos do módulo Controle de Ordens BMF";
            //groupGPBMF.Module.Id = "OMF";
            //groupGPBMF.Module.Name = "Controle de Ordens BMF";
            //groupGPBMF.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            //groupGPBMF.Index = 0;
            //groupGPBMF.AddDependency(_groupDependencyPmSinacorClient);
            //groupGPBMF.AddDependency(_groupDependencyPmSinacorServer);
            //groupGPBMF.AddDependency(_groupDependencyComSinacor);
            //groupGPBMF.AddDependency(_groupDependencyFwkSinacorClient);
            //groupGPBMF.AddDependency(_groupDependencyFwkSinacorServer);
            //groupGP.AddSubGroup(groupGPBMF);
            //AddActionCopy(groupGPBMF, "Copia dos arquivos dos processos do módulo Controle de Ordens BMF", @"Processos\BMF\");
            //AddActionUpdateConfigProcessManagerBMF(groupGPBMF, "Controle de Ordens BMF", "Bmf");
            //AddActionInstallProcessManagerInstance(groupGPBMF, "ControleOrdensBmf", "Instalação dos processos do módulo Controle de Ordens BMF");

            Group groupGPBmf = new Group();
            groupGPBmf.System = _systemInfo.Clone();
            groupGPBmf.Id = "ProcessManager-Bmf";
            groupGPBmf.Name = "Bmf";
            groupGPBmf.Description = "Processos do módulo BM&F";
            groupGPBmf.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupGPBmf.Index = 0;
            AddActionUpdateConfigProcessManagerBmf(groupGPBmf);

            Group groupGPBmfOrdens = new Group();
            groupGPBmfOrdens.System = _systemInfo.Clone();
            groupGPBmfOrdens.Id = "ProcessManager-BMF-Ordens";
            groupGPBmfOrdens.Name = "Controle de Ordens BM&F";
            groupGPBmfOrdens.Description = "Serviços do módulo Controle de Ordens BM&F";
            groupGPBmfOrdens.Module.Id = "OMF";
            groupGPBmfOrdens.Module.Name = "Controle de Ordens BM&F";
            groupGPBmfOrdens.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupGPBmfOrdens.Index = 0;
            groupGPBmfOrdens.AddDependency(_groupDependencyPmSinacorClient);
            groupGPBmfOrdens.AddDependency(_groupDependencyPmSinacorServer);
            groupGPBmfOrdens.AddDependency(_groupDependencyComSinacor);
            groupGPBmfOrdens.AddDependency(_groupDependencyFwkSinacorClient);
            groupGPBmfOrdens.AddDependency(_groupDependencyFwkSinacorServer);
            groupGPBmf.AddSubGroup(groupGPBmfOrdens);
            AddActionCopy(groupGPBmfOrdens, "Copia dos arquivos dos processos do módulo Controle de Ordens BM&F", @"Processos\BMF\");
            AddActionUpdateConfigProcessManagerOrdensBMF(groupGPBmfOrdens, "Controle de Ordens BM&F", "Bmf");
            AddActionInstallProcessManagerInstance(groupGPBmfOrdens, "ControleOrdensBmf", "Instalação dos processos do módulo Controle de Ordens BM&F");

            Group groupGPBmfFaturamento = new Group();
            groupGPBmfFaturamento.System = _systemInfo.Clone();
            groupGPBmfFaturamento.Id = "ProcessManager-BMF-Faturamento";
            groupGPBmfFaturamento.Name = "Faturamento BM&F";
            groupGPBmfFaturamento.Description = "Serviços do módulo Faturamento BM&F";
            groupGPBmfFaturamento.Module.Id = "BMF";
            groupGPBmfFaturamento.Module.Name = "Faturamento BM&F";
            groupGPBmfFaturamento.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupGPBmfFaturamento.Index = 1;
            groupGPBmfFaturamento.AddDependency(_groupDependencyPmSinacorClient);
            groupGPBmfFaturamento.AddDependency(_groupDependencyPmSinacorServer);
            groupGPBmfFaturamento.AddDependency(_groupDependencyComSinacor);
            groupGPBmfFaturamento.AddDependency(_groupDependencyFwkSinacorClient);
            groupGPBmfFaturamento.AddDependency(_groupDependencyFwkSinacorServer);
            groupGPBmf.AddSubGroup(groupGPBmfFaturamento);
            AddActionCopy(groupGPBmfFaturamento, "Copia dos arquivos dos processos do módulo Faturamento BM&F", @"Processos\BMF\");
            //AddActionUpdateConfigProcessManagerOrdensBMF(groupGPBmfFaturamento, "Faturamento BMF", "Bmf");
            AddActionInstallProcessManagerInstance(groupGPBmfFaturamento, "FaturamentoBmf", "Instalação dos processos do módulo Faturamento BM&F");

            groupGP.AddSubGroup(groupGPBmf);

            Group groupGPBovespa = new Group();
            groupGPBovespa.System = _systemInfo.Clone();
            groupGPBovespa.Id = "ProcessManager-Bovespa";
            groupGPBovespa.Name = "Bovespa";
            groupGPBovespa.Description = "Processos do módulo Bovespa";
            groupGPBovespa.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupGPBovespa.Index = 1;
            AddActionUpdateConfigProcessManagerBovespa(groupGPBovespa);

            Group groupGPBovespaOrdens = new Group();
            groupGPBovespaOrdens.System = _systemInfo.Clone();
            groupGPBovespaOrdens.Id = "ProcessManager-Bovespa-Ordens";
            groupGPBovespaOrdens.Name = "Controle de Ordens Bovespa";
            groupGPBovespaOrdens.Description = "Processos do módulo Controle de Ordens Bovespa";
            groupGPBovespaOrdens.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupGPBovespaOrdens.Module.Id = "ORD";
            groupGPBovespaOrdens.Module.Name = "Controle de Ordens Bovespa";
            groupGPBovespaOrdens.Index = 0;
            groupGPBovespaOrdens.AddDependency(_groupDependencyPmSinacorClient);
            groupGPBovespaOrdens.AddDependency(_groupDependencyPmSinacorServer);
            groupGPBovespaOrdens.AddDependency(_groupDependencyComSinacor);
            groupGPBovespaOrdens.AddDependency(_groupDependencyFwkSinacorClient);
            groupGPBovespaOrdens.AddDependency(_groupDependencyFwkSinacorServer);
            groupGPBovespa.AddSubGroup(groupGPBovespaOrdens);
            AddActionCopy(groupGPBovespaOrdens, "Copia dos arquivos dos processos do módulo Controle de Ordens Bovespa", @"Processos\Bovespa\");
            AddActionUpdateConfigProcessManagerBovespa(groupGPBovespaOrdens, "Controle de Ordens Bovespa", "Bovespa");
            AddActionInstallProcessManagerInstance(groupGPBovespaOrdens, "ControleOrdensBovespa", "Instalação dos processos do módulo Controle de Ordens Bovespa");

            Group groupGPBovespaFaturamento = new Group();
            groupGPBovespaFaturamento.System = _systemInfo.Clone();
            groupGPBovespaFaturamento.Id = "ProcessManager-Bovespa-Faturamento";
            groupGPBovespaFaturamento.Name = "Faturamento Bovespa";
            groupGPBovespaFaturamento.Description = "Processos do módulo Faturamento Bovespa";
            groupGPBovespaFaturamento.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupGPBovespaFaturamento.Module.Id = "BOL";
            groupGPBovespaFaturamento.Module.Name = "Faturamento Bovespa";
            groupGPBovespaFaturamento.Index = 1;
            groupGPBovespaFaturamento.AddDependency(_groupDependencyPmSinacorClient);
            groupGPBovespaFaturamento.AddDependency(_groupDependencyPmSinacorServer);
            groupGPBovespaFaturamento.AddDependency(_groupDependencyComSinacor);
            groupGPBovespaFaturamento.AddDependency(_groupDependencyFwkSinacorClient);
            groupGPBovespaFaturamento.AddDependency(_groupDependencyFwkSinacorServer);
            groupGPBovespa.AddSubGroup(groupGPBovespaFaturamento);
            AddActionCopy(groupGPBovespaFaturamento, "Copia dos arquivos dos processos do módulo Faturamento Bovespa", @"Processos\Bovespa\");
            //AddActionUpdateConfigProcessManager(groupGPBovespaFaturamento, "Faturamento Bovespa", "Bovespa");
            AddActionInstallProcessManagerInstance(groupGPBovespaFaturamento, "FaturamentoBovespa", "Instalação dos processos do módulo Faturamento Bovespa");

            groupGP.AddSubGroup(groupGPBovespa);

            Group groupGPClientes = new Group();
            groupGPClientes.System = _systemInfo.Clone();
            groupGPClientes.Id = "ProcessManager-Clientes";
            groupGPClientes.Name = "Clientes";
            groupGPClientes.Description = "Processos do módulo Clientes";
            groupGPClientes.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupGPClientes.Module.Id = "CLI";
            groupGPClientes.Module.Name = "Clientes";
            groupGPClientes.Index = 2;
            groupGPClientes.AddDependency(_groupDependencyPmSinacorClient);
            groupGPClientes.AddDependency(_groupDependencyPmSinacorServer);
            groupGPClientes.AddDependency(_groupDependencyComSinacor);
            groupGPClientes.AddDependency(_groupDependencyFwkSinacorClient);
            groupGPClientes.AddDependency(_groupDependencyFwkSinacorServer);
            groupGP.AddSubGroup(groupGPClientes);
            AddActionCopy(groupGPClientes, "Copia dos arquivos dos processos do módulo Clientes", @"Processos\Clientes\");
            AddActionUpdateConfigProcessManagerClientes(groupGPClientes, "Clientes", "Clientes");
            AddActionInstallProcessManagerInstance(groupGPClientes, "Clientes", "Instalação dos processos do módulo Clientes");

            Group groupGPContasCorrentes = new Group();
            groupGPContasCorrentes.System = _systemInfo.Clone();
            groupGPContasCorrentes.Id = "ProcessManager-ContasCorrentes";
            groupGPContasCorrentes.Name = "Contas Correntes";
            groupGPContasCorrentes.Description = "Processos do módulo Contas Correntes";
            groupGPContasCorrentes.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupGPContasCorrentes.Module.Id = "CCO";
            groupGPContasCorrentes.Module.Name = "Contas Correntes";
            groupGPContasCorrentes.Index = 3;
            groupGPContasCorrentes.AddDependency(_groupDependencyPmSinacorClient);
            groupGPContasCorrentes.AddDependency(_groupDependencyPmSinacorServer);
            groupGPContasCorrentes.AddDependency(_groupDependencyComSinacor);
            groupGPContasCorrentes.AddDependency(_groupDependencyFwkSinacorClient);
            groupGPContasCorrentes.AddDependency(_groupDependencyFwkSinacorServer);
            groupGP.AddSubGroup(groupGPContasCorrentes);
            AddActionCopy(groupGPContasCorrentes, "Copia dos arquivos dos processos do módulo Contas Correntes", @"Processos\ContaCorrente\");
            //AddActionUpdateConfigProcessManager(groupGPContasCorrentes, "Contas Correntes", "ContaCorrente");
            AddActionInstallProcessManagerInstance(groupGPContasCorrentes, "ContaCorrente", "Instalação dos processos do módulo Contas Correntes");

            Group groupGPTesouraria = new Group();
            groupGPTesouraria.System = _systemInfo.Clone();
            groupGPTesouraria.Id = "ProcessManager-Tesouraria";
            groupGPTesouraria.Name = "Tesouraria";
            groupGPTesouraria.Description = "Processos do módulo Tesouraria";
            groupGPTesouraria.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupGPTesouraria.Module.Id = "TES";
            groupGPTesouraria.Module.Name = "Tesouraria";
            groupGPTesouraria.Index = 4;
            groupGPTesouraria.AddDependency(_groupDependencyPmSinacorClient);
            groupGPTesouraria.AddDependency(_groupDependencyPmSinacorServer);
            groupGPTesouraria.AddDependency(_groupDependencyComSinacor);
            groupGPTesouraria.AddDependency(_groupDependencyFwkSinacorClient);
            groupGPTesouraria.AddDependency(_groupDependencyFwkSinacorServer);
            groupGP.AddSubGroup(groupGPTesouraria);
            AddActionCopy(groupGPTesouraria, "Copia dos arquivos dos processos do módulo Tesouraria", @"Processos\Tesouraria\", @"Processos\Solicitacoes\");
            AddActionUpdateConfigProcessManagerTesouraria(groupGPTesouraria, "Tesouraria", "Tesouraria", "Solicitacoes");
            AddActionInstallProcessManagerInstance(groupGPTesouraria, "Tesouraria", "Instalação dos processos do módulo Tesouraria");

            Group groupGPContasContasPagar = new Group();
            groupGPContasContasPagar.System = _systemInfo.Clone();
            groupGPContasContasPagar.Id = "ProcessManager-ContasPagar";
            groupGPContasContasPagar.Name = "Contas a Pagar";
            groupGPContasContasPagar.Description = "Processos do módulo Contas a Pagar";
            groupGPContasContasPagar.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            groupGPContasContasPagar.Module.Id = "CTP";
            groupGPContasContasPagar.Module.Name = "Contas a Pagar";
            groupGPContasContasPagar.Index = 5;
            groupGPContasContasPagar.AddDependency(_groupDependencyPmSinacorClient);
            groupGPContasContasPagar.AddDependency(_groupDependencyPmSinacorServer);
            groupGPContasContasPagar.AddDependency(_groupDependencyComSinacor);
            groupGPContasContasPagar.AddDependency(_groupDependencyFwkSinacorClient);
            groupGPContasContasPagar.AddDependency(_groupDependencyFwkSinacorServer);
            groupGP.AddSubGroup(groupGPContasContasPagar);
            AddActionCopy(groupGPContasContasPagar, "Copia dos arquivos dos processos do módulo Contas a Pagar", @"Processos\ContasPagar\");
            AddActionInstallProcessManagerInstance(groupGPContasContasPagar, "ContasPagar", "Instalação dos processos do módulo Contas a Pagar");

            config.SystemInfo.Groups.Add(groupGP);
        }

        private static void PopulateDataBase()
        {
            Group groupDatabase = new Group();
            groupDatabase.System = _systemInfo.Clone();
            groupDatabase.Id = "Database";
            groupDatabase.Name = "Banco de Dados";
            groupDatabase.Description = "Camada de Banco de Dados";
            groupDatabase.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Database);
            groupDatabase.Index = 3;
            config.SystemInfo.Groups.Add(groupDatabase);

            PopulateDataBaseConfig();
        }

        private static void PopulateDataBaseConfig()
        {
            config.DataBase.Versions.Add(
                new VersionInfo()
                {
                    Module = new Sinacor.Deployment.Setup.Configuration.Module() { Id = "BMF", Name = "Faturamento BM&F" },
                    Versions = new List<string>() { "2.20" }
                }
            );

            config.DataBase.Versions.Add(
                new VersionInfo()
                {
                    Module = new Sinacor.Deployment.Setup.Configuration.Module() { Id = "OMF", Name = "Controle de Ordens BM&F" },
                    Versions = new List<string>() { "2.20" }
                }
            );

            config.DataBase.Versions.Add(
                new VersionInfo()
                {
                    Module = new Sinacor.Deployment.Setup.Configuration.Module() { Id = "ORD", Name = "Controle de Ordens Bovespa" },
                    Versions = new List<string>() { "7.22" }
                }
            );

            config.DataBase.Versions.Add(
                new VersionInfo()
                {
                    Module = new Sinacor.Deployment.Setup.Configuration.Module() { Id = "BOL", Name = "Faturamento Bovespa" },
                    Versions = new List<string>() { "4.22" }
                }
            );

            config.DataBase.Versions.Add(
                new VersionInfo()
                {
                    Module = new Sinacor.Deployment.Setup.Configuration.Module() { Id = "CLI", Name = "Clientes" },
                    Versions = new List<string>() { "29.6" }
                }
            );

            config.DataBase.Versions.Add(
                new VersionInfo()
                {
                    Module = new Sinacor.Deployment.Setup.Configuration.Module() { Id = "CCO", Name = "Conta Corrente" },
                    Versions = new List<string>() { "29.6" }
                }
            );

            config.DataBase.Versions.Add(
                new VersionInfo()
                {
                    Module = new Sinacor.Deployment.Setup.Configuration.Module() { Id = "TES", Name = "Tesouraria" },
                    Versions = new List<string>() { "29.6" }
                }
            );
        }

        private static void PopulateDataBaseScript()
        {
            DataBaseScripts = new DataBaseScripts();

            Script scriptSystemCreate = new Script();
            scriptSystemCreate.Schema = Sinacor.Deployment.Setup.Configuration.Enums.SchemaType.System;
            scriptSystemCreate.Type = Sinacor.Deployment.Setup.Configuration.Enums.ScriptType.Create;
            scriptSystemCreate.Commands = GetCommandsFromFile("SchemaPrincipal.sql", 0, "[COMPANYUSER]", "[SYSTEMUSER]");
            DataBaseScripts.Scripts.Add(scriptSystemCreate);

            Script scriptSystemInsert = new Script();
            scriptSystemInsert.Schema = Sinacor.Deployment.Setup.Configuration.Enums.SchemaType.System;
            scriptSystemInsert.Type = Sinacor.Deployment.Setup.Configuration.Enums.ScriptType.Insert;
            scriptSystemInsert.Commands = GetCommandsFromFile("InsertPrincipal.sql", 0, "[COMPANYUSER]", "[SYSTEMUSER]");
            DataBaseScripts.Scripts.Add(scriptSystemInsert);

            Script scriptCompanyCreate = new Script();
            scriptCompanyCreate.Schema = Sinacor.Deployment.Setup.Configuration.Enums.SchemaType.Company;
            scriptCompanyCreate.Type = Sinacor.Deployment.Setup.Configuration.Enums.ScriptType.Create;
            scriptCompanyCreate.Commands = GetCommandsFromFile("SchemaEmpresa.sql", 1, "[COMPANYUSER]", "[SYSTEMUSER]");
            DataBaseScripts.Scripts.Add(scriptCompanyCreate);


            Script scriptCompanyInsert = new Script();
            scriptCompanyInsert.Schema = Sinacor.Deployment.Setup.Configuration.Enums.SchemaType.Company;
            scriptCompanyInsert.Type = Sinacor.Deployment.Setup.Configuration.Enums.ScriptType.Insert;
            scriptCompanyInsert.Commands = GetCommandsFromFile("InsertEmpresa.sql", 1, "[COMPANYUSER]", "[SYSTEMUSER]");
            DataBaseScripts.Scripts.Add(scriptCompanyInsert);

            Script scriptSystemDrop = new Script();
            scriptSystemDrop.Schema = Sinacor.Deployment.Setup.Configuration.Enums.SchemaType.System;
            scriptSystemDrop.Type = Sinacor.Deployment.Setup.Configuration.Enums.ScriptType.Drop;
            scriptSystemDrop.Commands = GetCommandsFromFile("DropSchemaPrincipal.sql", 0, "[COMPANYUSER]", "[SYSTEMUSER]");
            DataBaseScripts.Scripts.Add(scriptSystemDrop);

            Script scriptCompanyDrop = new Script();
            scriptCompanyDrop.Schema = Sinacor.Deployment.Setup.Configuration.Enums.SchemaType.Company;
            scriptCompanyDrop.Type = Sinacor.Deployment.Setup.Configuration.Enums.ScriptType.Drop;
            scriptCompanyDrop.Commands = GetCommandsFromFile("DropSchemaEmpresa.sql", 1, "[COMPANYUSER]", "[SYSTEMUSER]");
            DataBaseScripts.Scripts.Add(scriptCompanyDrop);

        }

        private static List<Command> GetCommandsFromFile(string file, Int32 companyId, string user, string masterUser)
        {
            StringBuilder sb = new StringBuilder();
            string rowTextFile = "";
            bool exec = false;
            List<Command> commands = new List<Command>();
            string RollBackCommand = "";
            System.IO.FileInfo fi = new System.IO.FileInfo(Path.Combine(Path.Combine(_outPutPath, "Scripts"), file));

            using (StreamReader sr = fi.OpenText())
            {
                while ((rowTextFile = sr.ReadLine()) != null)
                {
                    if ((rowTextFile.ToString().IndexOf("fim@@") >= 0) && (exec))
                    {
                        RollBackCommand = rowTextFile.ToString().Replace("fim@@", "");

                        Command command = new Command();
                        command.StringCommand = sb.ToString();

                        if (sb.ToString().ToUpper().Contains("CREATE "))
                            command.Type = Sinacor.Deployment.Setup.Configuration.Enums.CommandType.Create;
                        else if (sb.ToString().ToUpper().Contains("INSERT "))
                            command.Type = Sinacor.Deployment.Setup.Configuration.Enums.CommandType.Insert;
                        else if (sb.ToString().ToUpper().Contains("DROP "))
                            command.Type = Sinacor.Deployment.Setup.Configuration.Enums.CommandType.Drop;
                        else if (sb.ToString().ToUpper().Contains("DELETE "))
                            command.Type = Sinacor.Deployment.Setup.Configuration.Enums.CommandType.Delete;
                        else
                            command.Type = Sinacor.Deployment.Setup.Configuration.Enums.CommandType.Others;

                        command.UndoCommand = RollBackCommand;

                        if ((companyId != 0) && !(sb.ToString().ToLower().IndexOf("grant") >= 0) && !(sb.ToString().ToLower().IndexOf("revoke") >= 0))
                        {
                            command.ExecutionSchema = Sinacor.Deployment.Setup.Configuration.Enums.SchemaType.Company;
                        }
                        else
                        {
                            command.ExecutionSchema = Sinacor.Deployment.Setup.Configuration.Enums.SchemaType.System;
                        }


                        commands.Add(command);
                        exec = false;
                        sb.Remove(0, sb.Length);
                    }
                    else if ((rowTextFile.ToString().IndexOf("fim@@") >= 0) && (!exec))
                    {

                        sb.Remove(0, sb.Length);
                    }

                    if (rowTextFile.ToString().IndexOf("@@inicio") >= 0)
                    {
                        exec = true;
                    }


                    if (rowTextFile.ToString().IndexOf("-@@-Usuario-@-Sistema-@@-") >= 0)
                    {
                        rowTextFile = rowTextFile.Replace("-@@-Usuario-@-Sistema-@@-", masterUser);
                    }

                    if (rowTextFile.ToString().IndexOf("-@@-Usuario-@@-") >= 0)
                    {
                        rowTextFile = rowTextFile.Replace("-@@-Usuario-@@-", user);
                    }

                    if (!(rowTextFile.ToString().IndexOf("@@inicio") >= 0) && !(rowTextFile.ToString().IndexOf("fim@@") >= 0) && !(rowTextFile.ToString().IndexOf("C--") >= 0))
                    {
                        sb.Append(rowTextFile.ToString());
                        sb.Append(" ");
                    }
                }
            }
            return commands;
        }

        //private static void PopulateMSMQ()
        //{
        //    Group groupMSMQ = new Group();
        //    groupMSMQ.System = _systemInfo.Clone();
        //    groupMSMQ.Id = "MSMQ";
        //    groupMSMQ.Name = "Fila do Message Queue";
        //    groupMSMQ.Description = "Fila do Message Queue";
        //    groupMSMQ.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
        //    groupMSMQ.Module.Id = "INFRA";
        //    groupMSMQ.Module.Name = "Componentes do Framework";
        //    groupMSMQ.Index = 4;
        //    AddActionInstallMessageQueue(groupMSMQ, "Instalação da fila MSMQ para o serviço de Log do Sinacor");
        //    config.SystemInfo.Groups.Add(groupMSMQ);
        //}

        private static void PopulateDependencies()
        {
            _groupDependencyFwkSinacorCore = new Group();
            _groupDependencyFwkSinacorCore.System = _systemInfo.Clone();
            _groupDependencyFwkSinacorCore.Id = "Sinacor-Framework-Core";
            _groupDependencyFwkSinacorCore.Name = "Serviços";
            _groupDependencyFwkSinacorCore.Description = "Núcleo do Framework do Sinacor";
            _groupDependencyFwkSinacorCore.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            _groupDependencyFwkSinacorCore.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            _groupDependencyFwkSinacorCore.Module.Id = "INFRA";
            _groupDependencyFwkSinacorCore.Module.Name = "Componentes do Framework";
            _groupDependencyFwkSinacorCore.Index = 0;
            _groupDependencyFwkSinacorCore.Dependencies = new List<Group>();
            AddActionCopy(_groupDependencyFwkSinacorCore, "Copia dos arquivos do framework do Sinacor", @"Common\", @"ExternalRef\", @"Settings\", @"Versions\", @"Infra\Tools\LanguageGenerator\");
            AddActionInstallAssembly(_groupDependencyFwkSinacorCore, "Instalação dos arquivos do framework do Sinacor", @"Common\", @"ExternalRef\");
            AddCreateShortcut(_groupDependencyFwkSinacorCore, "Criação dos atalhos", null);
            AddActionUpdateEndpoint(_groupDependencyFwkSinacorCore);
            AddActionUpdateWindowsRegistryClient(_groupDependencyFwkSinacorCore, "Criação do registro de windows");

            FolderInfo core = new FolderInfo()
            {
                Source = @"Bin\Sinacor\Core\",
                Destination = @"Sinacor\Core\",
                Files = new List<string>() { "Sinacor.Infra.Core.Licensing.LicensingPrincipal.dll", "Sinacor.Infra.Core.LicensingLibrary.dll", "Sinacor.Infra.Core.LicensingValidator.dll" },
            };

            FolderInfo settings = new FolderInfo()
            {
                Source = @"Bin\Sinacor\",
                Destination = @"Sinacor\",
                Files = new List<string> { "GeneralSettings.config" }
            };

            ((Copy)(_groupDependencyFwkSinacorCore.Actions[0])).Folders.Insert(0, core);
            ((Copy)(_groupDependencyFwkSinacorCore.Actions[0])).Folders.Insert(0, settings);
            ((InstallAssembly)(_groupDependencyFwkSinacorCore.Actions[1])).Folders.Insert(0, core);

            _groupDependencyFwkSinacorClient = new Group();
            _groupDependencyFwkSinacorClient.System = _systemInfo.Clone();
            _groupDependencyFwkSinacorClient.Id = "Sinacor-Framework-Client";
            _groupDependencyFwkSinacorClient.Name = "Sinacor Framework Client";
            _groupDependencyFwkSinacorClient.Description = "Cliente do Framework do Sinacor";
            _groupDependencyFwkSinacorClient.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            _groupDependencyFwkSinacorClient.Module.Id = "INFRA";
            _groupDependencyFwkSinacorClient.Module.Name = "Componentes do Framework";
            _groupDependencyFwkSinacorClient.Index = 0;
            _groupDependencyFwkSinacorClient.Dependencies = new List<Group>();
            _groupDependencyFwkSinacorClient.AddDependency(_groupDependencyFwkSinacorCore);
            AddActionCopy(_groupDependencyFwkSinacorClient, "Copia dos arquivos do framework do Sinacor", @"UI\Infra\", @"UI\Application\Infra\", @"Certificates\UI", @"Tools\ErrorLogCollector");
            AddActionInstallAssembly(_groupDependencyFwkSinacorClient, "Instalação dos arquivos do framework do Sinacor", @"UI\Infra\");
            AddActionInstallClientCertificate(_groupDependencyFwkSinacorClient, "Instalação dos certificados do framework do Sinacor");
            AddCreateShortcut(_groupDependencyFwkSinacorClient, "Criação dos atalhos", null);

            _groupDependencyFwkSinacorServer = new Group();
            _groupDependencyFwkSinacorServer.System = _systemInfo.Clone();
            _groupDependencyFwkSinacorServer.Id = "Sinacor-Framework-Server";
            _groupDependencyFwkSinacorServer.Name = "Sinacor Framework Server";
            _groupDependencyFwkSinacorServer.Description = "Servidor do Framework do Sinacor";
            _groupDependencyFwkSinacorServer.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            _groupDependencyFwkSinacorServer.Module.Id = "INFRA";
            _groupDependencyFwkSinacorServer.Module.Name = "Componentes do Framework";
            _groupDependencyFwkSinacorServer.Index = 0;
            _groupDependencyFwkSinacorServer.Dependencies = new List<Group>();
            _groupDependencyFwkSinacorServer.AddDependency(_groupDependencyFwkSinacorCore);
            AddActionCopy(_groupDependencyFwkSinacorServer, "Copia dos arquivos do framework do Sinacor", @"Servicos\Infra\", @"Certificates\Servicos", @"Tools\ErrorLogCollector");
            AddActionInstallAssembly(_groupDependencyFwkSinacorServer, "Instalação dos arquivos do framework do Sinacor", @"Servicos\Infra\");
            AddActionInstallServerCertificate(_groupDependencyFwkSinacorServer, "Instalação dos certificados do framework do Sinacor");
            AddActionUpdateWindowsRegistry(_groupDependencyFwkSinacorServer, "Criação do registro de windows");
            AddCreateShortcut(_groupDependencyFwkSinacorServer, "Criação dos atalhos", null);

            _groupDependencyPmSinacorClient = new Group();
            _groupDependencyPmSinacorClient.System = _systemInfo.Clone();
            _groupDependencyPmSinacorClient.Id = "Sinacor-ProcessManager-Client";
            _groupDependencyPmSinacorClient.Name = "Sinacor-ProcessManager-Client";
            _groupDependencyPmSinacorClient.Description = "Cliente do Gerenciador de Processos do Sinacor";
            _groupDependencyPmSinacorClient.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            _groupDependencyPmSinacorClient.Module.Id = "INFRA";
            _groupDependencyPmSinacorClient.Module.Name = "Componentes do Framework";
            _groupDependencyPmSinacorClient.Index = 0;
            _groupDependencyPmSinacorClient.AddDependency(_groupDependencyFwkSinacorClient);
            AddActionCopy(_groupDependencyPmSinacorClient, "Copia dos arquivos do gerenciador de processos do Sinacor", @"Core\ProcessManager\Client");
            AddActionInstallAssembly(_groupDependencyPmSinacorClient, "Instalação dos arquivos do gerenciador do processos do Sinacor", @"Core\ProcessManager\Client");

            _groupDependencyPmSinacorServer = new Group();
            _groupDependencyPmSinacorServer.System = _systemInfo.Clone();
            _groupDependencyPmSinacorServer.Id = "Sinacor-ProcessManager-Server";
            _groupDependencyPmSinacorServer.Name = "Sinacor-ProcessManager-Server";
            _groupDependencyPmSinacorServer.Description = "Servidor do Gerenciador de Processos do Sinacor";
            _groupDependencyPmSinacorServer.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            _groupDependencyPmSinacorServer.Module.Id = "INFRA";
            _groupDependencyPmSinacorServer.Module.Name = "Componentes do Framework";
            _groupDependencyPmSinacorServer.Index = 0;
            _groupDependencyPmSinacorServer.AddDependency(_groupDependencyFwkSinacorServer);
            AddActionCopy(_groupDependencyPmSinacorServer, "Copia dos arquivos do gerenciador de processos do Sinacor", @"Core\ProcessManager\Data", @"Core\ProcessManager\Server");
            AddActionInstallAssembly(_groupDependencyPmSinacorServer, "Instalação dos arquivos do gerenciador do processos do Sinacor", @"Core\ProcessManager\Data", @"Core\ProcessManager\Server");

            _groupDependencyComSinacor = new Group();
            _groupDependencyComSinacor.System = _systemInfo.Clone();
            _groupDependencyComSinacor.Id = "Sinacor-Communication";
            _groupDependencyComSinacor.Name = "Sinacor-Communication";
            _groupDependencyComSinacor.Description = "Camada de Comunicação do Sinacor";
            _groupDependencyComSinacor.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Client);
            _groupDependencyComSinacor.Layers.Add(PSE.Deployment.SetupBase.Configuration.Enums.Layer.Server);
            _groupDependencyComSinacor.Module.Id = "INFRA";
            _groupDependencyComSinacor.Module.Name = "Componentes do Framework";
            _groupDependencyComSinacor.Index = 0;
            _groupDependencyPmSinacorServer.AddDependency(_groupDependencyFwkSinacorClient);
            _groupDependencyPmSinacorServer.AddDependency(_groupDependencyFwkSinacorServer);
            AddActionCopy(_groupDependencyComSinacor, "Copia dos arquivos da Camada de comunicação do Sinacor", @"Core\Communication\");
            AddActionInstallAssembly(_groupDependencyComSinacor, "Instalação dos arquivos da Camada de comunicação do Sinacor", @"Core\Communication\");
        }

        private static void AddActionCopy(Group group, string description, params string[] destinations)
        {
            Copy c = new Copy();
            c.Id = "Copy-" + group.Id;
            c.Description = description;
            c.GroupId = group.Id;
            c.Index = 0;

            foreach (string destination in destinations)
            {
                if (!System.IO.Path.HasExtension(destination))
                {
                    c.Folders.Add(new FolderInfo()
                    {
                        Source = @"Bin\" + group.System.Id + @"\" + destination,
                        Destination = group.System.Id + @"\" + destination,
                    });
                }
                else
                {
                    c.Folders.Add(new FolderInfo()
                    {
                        Source = @"Bin\" + group.System.Id + @"\" + System.IO.Path.GetDirectoryName(destination) + @"\",
                        Destination = group.System.Id + @"\" + System.IO.Path.GetDirectoryName(destination) + @"\",
                        Files = new List<string> { System.IO.Path.GetFileName(destination) }
                    });
                }
            }

            group.Actions.Add(c);
        }

        private static void AddActionInstallWcfService(Group group, string processName, string path, string description, params string[] destinations)
        {
            InstallWcfService c = new InstallWcfService();
            c.Id = "InstallWcfService-" + group.Id;
            c.Description = description;
            c.GroupId = group.Id;
            c.Index = 20;

            foreach (string destination in destinations)
            {
                c.Services.Add(new PSE.Deployment.SetupBase.Configuration.WcfService()
                {
                    ProcessName = processName,
                    Path = path,
                    ServerName = "localhost",
                    Folder = new FolderInfo()
                    {
                        Source = @"Bin\" + group.System.Id + @"\" + destination,
                        Destination = group.System.Id + @"\" + destination,
                    }
                });
            }

            group.Actions.Add(c);
        }

        private static void AddActionInstallWcfServiceMain(Group group, string description)
        {
            InstallWcfServiceMain c = new InstallWcfServiceMain();
            c.Id = "InstallWcfServiceMain-" + group.Id;
            c.Description = description;
            c.GroupId = group.Id;
            c.Index = 20;
            c.HttpPort = 801;
            c.TcpPort = 808;
            c.Folder = new FolderInfo() { Source = @"Bin\Sinacor\Servicos\", Destination = @"Sinacor\Servicos\" };

            group.Actions.Add(c);
        }

        private static void AddActionInstallProcessManagerProduct(Group group, string description)
        {
            InstallProcessManagerProduct c = new InstallProcessManagerProduct();
            c.Id = "InstallProcessManagerProduct-" + group.Id;
            c.Description = description;
            c.GroupId = group.Id;
            c.Index = 20;

            c.ProductName = "Sinacor";

            group.Actions.Add(c);
        }

        private static void AddActionInstallProcessManagerInstance(Group group, string instance_name, string description)
        {
            InstallProcessManagerInstance c = new InstallProcessManagerInstance();
            c.Id = "InstallProcessManagerInstance-" + group.Id;
            c.Description = description;
            c.GroupId = group.Id;
            c.Index = 20;

            c.Instances.Add(GetInstance(instance_name));

            if (instance_name == "ControleOrdensBmf")
            {
                c.Instances.Add(GetInstance("FaturamentoBmf"));
            }

            group.Actions.Add(c);
        }

        private static void AddActionInstallAssembly(Group group, string description, params string[] destinations)
        {
            InstallAssembly c = new InstallAssembly();
            c.Id = "InstallAssembly-" + group.Id;
            c.Description = description;
            c.GroupId = group.Id;
            c.Index = 1;

            foreach (string destination in destinations)
            {
                c.Folders.Add(new FolderInfo()
                {
                    Source = @"Bin\" + group.System.Id + @"\" + destination,
                    Destination = group.System.Id + @"\" + destination,
                });
            }

            group.Actions.Add(c);
        }

        private static void AddActionInstallWindowsService(Group group, string description, params string[][] services)
        {
            InstallWindowsService c = new InstallWindowsService();
            c.Id = "InstallWindowsService-" + group.Id;
            c.Description = description;
            c.GroupId = group.Id;
            c.Index = 30;

            foreach (string[] service in services)
            {
                c.Services.Add(new PSE.Deployment.SetupBase.Configuration.WindowsService()
                {
                    ServiceName = service[0],
                    DisplayName = service[1],
                    Description = service[2],
                    ServiceFile = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Source = @"Bin\" + group.System.Id + @"\" + service[3],
                        Destination = group.System.Id + @"\" + service[3],
                        FileName = service[4],
                    },
                    ConfigFile = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Source = @"Bin\" + group.System.Id + @"\" + service[3],
                        Destination = group.System.Id + @"\" + service[3],
                        FileName = service[4],
                    },
                    Start = Convert.ToBoolean(service[6])
                });
            }

            group.Actions.Add(c);
        }

        private static void AddActionInstallClientCertificate(Group group, string description)
        {
            InstallCertificate c = new InstallCertificate();
            c.Id = "InstallCertificate-" + group.Id;
            c.Description = description;
            c.GroupId = group.Id;
            c.Index = 2;

            c.Certificates.Add(new PSE.Deployment.SetupBase.Configuration.Certificate()
            {
                StoreName = System.Security.Cryptography.X509Certificates.StoreName.Root,
                Password = "t/g6WwmIaHaw/Q7pF436Yp/mtwDabm5R",
                File = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                {
                    Source = @"Bin\Sinacor\Certificates\UI\",
                    Destination = group.System.Id + @"\" + @"Certificates\UI\",
                    FileName = "WCFQuickstartRoot.pfx",
                }
            });

            c.Certificates.Add(new PSE.Deployment.SetupBase.Configuration.Certificate()
            {
                StoreName = System.Security.Cryptography.X509Certificates.StoreName.TrustedPeople,
                Password = "t/g6WwmIaHaw/Q7pF436Yp/mtwDabm5R",
                File = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                {
                    Source = @"Bin\Sinacor\Certificates\UI\",
                    Destination = group.System.Id + @"\" + @"Certificates\UI\",
                    FileName = "SinacorSTSAuthority.pfx",
                }
            });

            group.Actions.Add(c);
        }

        private static void AddActionInstallServerCertificate(Group group, string description)
        {
            InstallCertificate c = new InstallCertificate();
            c.Id = "InstallCertificate-" + group.Id;
            c.Description = description;
            c.GroupId = group.Id;
            c.Index = 2;

            c.Certificates.Add(new PSE.Deployment.SetupBase.Configuration.Certificate()
            {
                StoreName = System.Security.Cryptography.X509Certificates.StoreName.Root,
                Password = "t/g6WwmIaHaw/Q7pF436Yp/mtwDabm5R",
                File = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                {
                    Source = @"Bin\Sinacor\Certificates\Servicos\",
                    Destination = group.System.Id + @"\" + @"Certificates\Servicos\",
                    FileName = "WCFQuickstartRoot.pfx",
                }
            });

            c.Certificates.Add(new PSE.Deployment.SetupBase.Configuration.Certificate()
            {
                StoreName = System.Security.Cryptography.X509Certificates.StoreName.TrustedPeople,
                Password = "t/g6WwmIaHaw/Q7pF436Yp/mtwDabm5R",
                File = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                {
                    Source = @"Bin\Sinacor\Certificates\Servicos\",
                    Destination = group.System.Id + @"\" + @"Certificates\Servicos\",
                    FileName = "SinacorService.pfx",
                }
            });

            c.Certificates.Add(new PSE.Deployment.SetupBase.Configuration.Certificate()
            {
                StoreName = System.Security.Cryptography.X509Certificates.StoreName.TrustedPeople,
                Password = "t/g6WwmIaHaw/Q7pF436Yp/mtwDabm5R",
                File = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                {
                    Source = @"Bin\Sinacor\Certificates\Servicos\",
                    Destination = group.System.Id + @"\" + @"Certificates\Servicos\",
                    FileName = "SinacorSTSAuthority.pfx",
                }
            });

            group.Actions.Add(c);
        }

        //private static void AddActionInstallMessageQueue(Group group, string description)
        //{
        //    InstallMessageQueue c = new InstallMessageQueue();
        //    c.Id = "InstallMessageQueue-" + group.Id;
        //    c.Description = description;
        //    c.GroupId = group.Id;
        //    c.Index = 0;

        //    Queue q = new Queue();
        //    q.MachineName = ".";
        //    q.QueueName = "SinacorLogging";
        //    q.LocationType = PSE.Deployment.SetupBase.Configuration.Enums.QueueLocationType.Private;
        //    q.InstallationType = PSE.Deployment.SetupBase.Configuration.Enums.QueueInstallationType.Local;

        //    c.Queues = new List<Queue>();
        //    c.Queues.Add(q);

        //    group.Actions.Add(c);
        //}

        private static void AddActionUpdateWindowsRegistry(Group group, string description)
        {
            UpdateWindowsRegistry c = new UpdateWindowsRegistry();
            c.Id = "UpdateWindowsRegistry-" + group.Id;
            c.Description = description;
            c.GroupId = group.Id;
            c.Index = 3;

            c.Keys.Add(new RegistryKey()
            {
                Name = @"SOFTWARE\SINACOR"
            });

            c.Keys.Add(new RegistryKey()
            {
                Name = @"SOFTWARE\SINACOR",
                Values = new List<RegistryValue>() 
                { 
                    new RegistryValue(){ Name = "ApplicationRootDirectory", Description="ApplicationRootDirectory", XPath = "/SinacorParameter/@FullInstallationPath", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = false, Type = XmlTagType.String }
                }
            });

            c.Keys.Add(new RegistryKey()
            {
                Name = @"SOFTWARE\SINACOR",
                Values = new List<RegistryValue>() 
                { 
                    new RegistryValue(){ Name = "SystemDescription", Description="SystemDescription", Value = "Sinacor", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = false, Type = XmlTagType.String }
                }
            });

            c.Keys.Add(new RegistryKey()
            {
                Name = @"SOFTWARE\SINACOR\Infra.Data",
                Title = "Banco de Dados",
                Description = "Banco de Dados",
                Values = new List<RegistryValue>() 
                { 
                    new RegistryValue(){ Name = "MaxPoolSize", Description="MaxPoolSize", Value = "15", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String, IsVisible = false, Type = XmlTagType.Integer },
                    new RegistryValue(){ Name = "MinPoolSize", Description="MinPoolSize", Value = "1", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = false, Type = XmlTagType.Integer },
                    new RegistryValue(){ Name = "User", Description="Usuário", XPath = "/SinacorParameter/DataBase/ConnectionInfo/@User", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = true, Type = XmlTagType.String },
                    new RegistryValue(){ Name = "Password", Description="Senha", XPath = "/SinacorParameter/DataBase/ConnectionInfo/@Password", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String, IsEncrypted=true, EncryptionAlgorithm=PSE.Deployment.SetupBase.Configuration.Enums.CryptographyAlgorithm.DES_InfraData, IsVisible = true, Type = XmlTagType.Password },
                    new RegistryValue(){ Name = "ConnectionTimeout", Description="ConnectionTimeout", Value = "60", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = false, Type = XmlTagType.Integer },
                    new RegistryValue(){ Name = "ConnectionLifetime", Description="ConnectionLifetime", Value = "120", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = false, Type = XmlTagType.Integer },
                    new RegistryValue(){ Name = "DecrPoolSize", Description="DecrPoolSize", Value = "1", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = false, Type = XmlTagType.Integer },
                    new RegistryValue(){ Name = "IncrPoolSize", Description="IncrPoolSize", Value = "5", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = false, Type = XmlTagType.Integer },
                    new RegistryValue(){ Name = "Pooling", Description="Pooling", Value = "true", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = false, Type = XmlTagType.Boolean },
                }
            });

            c.Keys.Add(new RegistryKey()
            {
                Name = @"SOFTWARE\SINACOR\Infra.Data\Config",
                Title = "Encriptação de senhas",
                Description = "Encriptação de senhas",
                Values = new List<RegistryValue>() 
                { 
                    new RegistryValue(){ Name = "IsEncrypted", Description="Encriptar", XPath = "/SinacorParameter/DataBase/ConnectionInfo/@IsEncryptedString", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = true, Type = XmlTagType.Integer }
                }
            });

            c.Keys.Add(new RegistryKey()
            {
                Name = @"SOFTWARE\SINACOR\Infra.Data\Instances",
                Title = "Instância do Banco de Dados",
                Description = "Instância do Banco de Dados",
                Values = new List<RegistryValue>() 
                { 
                    new RegistryValue(){ Name = "Default", Description="TNS Oracle", XPath = "/SinacorParameter/DataBase/ConnectionInfo/@TNSName", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = true, Type = XmlTagType.String }
                }
            });

            //c.Keys.Add(new RegistryKey()
            //{
            //    Name = @"SOFTWARE\SINACOR\ServiceReferences",
            //    Title = "Serviços",
            //    Description = "Serviços",
            //    Values = new List<RegistryValue>() 
            //    { 
            //        new RegistryValue(){ Name = "ConfigPathServiceInstance", Description="Caminho dos serviços do Sinacor", XPath = "/SinacorParameter/@ConfigPathServiceInstance", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = false, Type = XmlTagType.String }
            //    }
            //});

            //c.Keys.Add(new RegistryKey()
            //{
            //    Name = @"SOFTWARE\SINACOR\Logging",
            //    Title = "Log",
            //    Description = "Log",
            //    Values = new List<RegistryValue>() 
            //    { 
            //        new RegistryValue(){ Name = "AlternativeLogFilePath", Description="Caminho alternativo para a gravação do Log", XPath = "/SinacorParameter/@AlternativeLogFilePath", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = true, Type = XmlTagType.String },
            //        new RegistryValue(){ Name = "MSMQPath", Description="Caminho da fila do MSMQ", XPath = "/SinacorParameter/SetupConfiguration/SystemInfo/Groups/Group[@Id='MSMQ']/Actions/ActionBase[@Id='InstallMessageQueue-MSMQ']/Queues/Queue/@FullPath", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = true, Type = XmlTagType.String }
            //    }
            //});

            c.Keys.Add(new RegistryKey()
            {
                Name = @"SOFTWARE\SINACOR\Session",
                Title = "Sessão",
                Description = "Sessão",
                Values = new List<RegistryValue>() 
                { 
                    new RegistryValue(){ Name = "TimeOut", Description="TimeOut", Value = "5000", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = false, Type = XmlTagType.Integer }
                }
            });

            group.Actions.Add(c);
        }

        private static void AddActionUpdateWindowsRegistryClient(Group group, string description)
        {
            UpdateWindowsRegistry c = new UpdateWindowsRegistry();
            c.Id = "UpdateWindowsRegistry-" + group.Id;
            c.Description = description;
            c.GroupId = group.Id;
            c.Index = 3;

            c.Keys.Add(new RegistryKey()
            {
                Name = @"SOFTWARE\SINACOR",
                Values = new List<RegistryValue>() 
                { 
                    new RegistryValue(){ Name = "ApplicationRootDirectory", Description="ApplicationRootDirectory", XPath = "/SinacorParameter/@FullInstallationPath", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = false, Type = XmlTagType.String }
                }
            });

            c.Keys.Add(new RegistryKey()
            {
                Name = @"SOFTWARE\SINACOR",
                Values = new List<RegistryValue>() 
                { 
                    new RegistryValue(){ Name = "SystemDescription", Description="SystemDescription", Value = "Sinacor", RegistryValueKind = Microsoft.Win32.RegistryValueKind.String , IsVisible = false, Type = XmlTagType.String }
                }
            });

            group.Actions.Add(c);
        }

        private static void AddCreateShortcut(Group group, string description, params object[][] destinations)
        {
            CreateShortcut c = new CreateShortcut();
            c.Id = "CreateShortcut-" + group.Id;
            c.Description = description;
            c.GroupId = group.Id;
            c.Index = 10;

            //if (group.Id == "Sinacor-Framework-Client")
            //{
            //    c.Shortcuts.Add(new Shortcut()
            //    {
            //        Executable = new PSE.Deployment.SetupBase.Configuration.FileInfo()
            //        {
            //            Destination = @"Sinacor\Tools\ErrorLogCollector\",
            //            FileName = "ErrorLogCollectorClient.exe",
            //        },
            //        ShotcutFile = new PSE.Deployment.SetupBase.Configuration.FileInfo()
            //        {
            //            Destination = @"Sinacor\",
            //            FileName = "Coletor de Log de Erros - Cliente.lnk",
            //        },
            //        SpecialFolders = new List<PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder>() { PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder.StartMenu }
            //    });
            //}
            //else if (group.Id == "Sinacor-Framework-Server")
            //{
            //    c.Shortcuts.Add(new Shortcut()
            //    {
            //        Executable = new PSE.Deployment.SetupBase.Configuration.FileInfo()
            //        {
            //            Destination = @"Sinacor\Tools\ErrorLogCollector\",
            //            FileName = "ErrorLogCollectorServer.exe",
            //        },
            //        ShotcutFile = new PSE.Deployment.SetupBase.Configuration.FileInfo()
            //        {
            //            Destination = @"Sinacor\",
            //            FileName = "Coletor de Log de Erros - Servidor.lnk",
            //        },
            //        SpecialFolders = new List<PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder>() { PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder.StartMenu }
            //    });
            //}
            if (group.Id == "Sinacor-Framework-Core")
            {
                c.Shortcuts.Add(new Shortcut()
                {
                    Executable = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Destination = @"Sinacor\Setup-v1\",
                        FileName = "SinacorConfigurationManager.exe",
                    },
                    Icon = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Destination = @"Sinacor\Setup-v1\",
                        FileName = "Sinacor.ico",
                    },
                    ShotcutFile = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Destination = @"Sinacor\",
                        FileName = "Configurador do Sinacor.lnk",
                    },
                    SpecialFolders = new List<PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder>() { PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder.Desktop, PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder.StartMenu }
                });


                c.Shortcuts.Add(new Shortcut()
                {
                    Executable = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Destination = @"Sinacor\Setup-v1\",
                        FileName = "SetupUninstall.exe",
                    },
                    Icon = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Destination = @"Sinacor\Setup-v1\",
                        FileName = "Sinacor.ico",
                    },
                    ShotcutFile = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Destination = @"Sinacor\",
                        FileName = "Setup.lnk",
                    },
                    SpecialFolders = new List<PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder>() { PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder.StartMenu }
                });

                c.Shortcuts.Add(new Shortcut()
                {
                    Executable = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Destination = @"Sinacor\Setup-v1\Guides\pt-br\",
                        FileName = "UserGuide.pdf",
                    },
                    ShotcutFile = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Destination = @"Sinacor\Manuais\Português\",
                        FileName = "Manual do Usuário.lnk",
                    },
                    SpecialFolders = new List<PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder>() { PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder.StartMenu }
                });

                c.Shortcuts.Add(new Shortcut()
                {
                    Executable = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Destination = @"Sinacor\Setup-v1\Guides\pt-br\",
                        FileName = "InstallationGuide.pdf",
                    },
                    ShotcutFile = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Destination = @"Sinacor\Manuais\Português\",
                        FileName = "Manual de Instalação.lnk",
                    },
                    SpecialFolders = new List<PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder>() { PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder.StartMenu }
                });

                c.Shortcuts.Add(new Shortcut()
                {
                    Executable = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Destination = @"Sinacor\Versions\",
                        FileName = "SinacorVersions.exe",
                        Arguments = "1"
                    },
                    Icon = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Destination = @"Sinacor\Versions\",
                        FileName = "Versions.ico",
                    },
                    ShotcutFile = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                    {
                        Destination = @"Sinacor\",
                        FileName = "Visualizador de Versões do Sinacor.lnk",
                    },
                    SpecialFolders = new List<PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder>() { PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder.StartMenu }
                });
            }
            else
            {
                if (destinations != null)
                {
                    foreach (object[] destination in destinations)
                    {
                        c.Shortcuts.Add(new Shortcut()
                        {
                            Executable = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                            {
                                Source = @"Bin\" + group.System.Id + @"\" + destination[0],
                                Destination = group.System.Id + @"\" + destination[0],
                                FileName = destination[1].ToString(),
                            },
                            Icon = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                            {
                                Source = @"Bin\" + group.System.Id + @"\" + destination[2],
                                Destination = group.System.Id + @"\" + destination[2],
                                FileName = destination[3].ToString(),
                            },
                            ShotcutFile = new PSE.Deployment.SetupBase.Configuration.FileInfo()
                            {
                                Destination = destination[4].ToString(),
                                FileName = destination[5].ToString(),
                            },
                            SpecialFolders = (List<PSE.Deployment.SetupBase.Configuration.Enums.SpecialFolder>)destination[6]
                        });
                    }
                }
            }

            group.Actions.Add(c);
        }

        private static void AddActionUpdateEndpoint(Group group)
        {
            UpdateConfig c = new UpdateConfig();
            c.Id = "UpdateConfig-" + group.Id;
            c.Description = "Atualizaçao de config";
            c.GroupId = group.Id;
            c.Index = 15;
            c.XmlFiles = new List<XmlFile>();

            XmlFile xmlFile = new XmlFile()
            {
                Description = "Configuração do endereço do servidor",
                Title = "Geral",
                Folder = new FolderInfo()
                {
                    Source = @"Bin\Sinacor\",
                    Destination = @"Sinacor\",
                    IgnoreFiles = new List<string> 
                    {
                        "Infra.Authorization.config",
                        "Infra.FileTransfer.config", 
                        "Infra.Security.config",
                        "Sinacor.Service.Infra.AuthorizationService.Service.dll.config",
                        "Sinacor.Servico.Infra.FileTransfer.Service.dll.config",
                        "Sinacor.Servico.Infra.KeepAlive.Service.dll.config",
                        "Sinacor.Servico.Infra.Licensing.Service.dll.config",
                        "STSHosterService.exe.config",
                        "SinacorSetup.exe.config",
                        "SetupGenerator.exe.config",
                        "SetupConsole.exe.config",
                        "Sinacor.Infra.Services.SecurityTokenService.Services.dll.config",
                        @"Infra Services\web.config"
                    }
                },
            };

            //xmlFile.Tags.Add(new XmlTag()
            //{
            //    Description = "Servidor dos módulos",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Endpoint,
            //    Value = "localhost",
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath ="/configuration/system.serviceModel/client/endpoint/@address" }
            //});

            //xmlFile.Tags.Add(new XmlTag()
            //{
            //    Description = "Porta do servidor dos módulos",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.EndpointPort,
            //    Value = "808",
            //    IsVisible = false,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath ="/configuration/system.serviceModel/client/endpoint/@address" }
            //});

            xmlFile.Tags.Add(new XmlTag()
            {
                Description = "Servidor de Autenticação",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Endpoint,
                Value = "localhost",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/applicationConfiguration/servicesConfiguration/@issuerAddress" } }
            });

            //xmlFile.Tags.Add(new XmlTag()
            //{
            //    Description = "Porta do servidor de Autenticação",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.EndpointPort,
            //    Value = "62003",
            //    IsVisible = false,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/applicationConfiguration/servicesConfiguration/@issuerAddress" }}
            //});

            xmlFile.Tags.Add(new XmlTag()
            {
                Description = "Servidor do Gerenciador de Processos",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Endpoint,
                Value = "localhost",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/applicationConfiguration/inteligenceManagerConfiguration/@inteligenceManagerAddress" } }
            });

            xmlFile.Tags.Add(new XmlTag()
            {
                Description = "Tipo de Criptografia",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Endpoint,
                IsList = true,
                ControlItemSource = new List<XmlTagItemSource> {
                    new XmlTagItemSource { Name = "Básico", TagValue = "Basic", TagItemValue = "netTcpBinding" },
                    new XmlTagItemSource { Name = "Autenticação Windows", TagValue = "Transport", TagItemValue = "netTcpBinding" },
                    new XmlTagItemSource { Name = "Certificado", TagValue = "Federated", TagItemValue = "customBinding" }
                },
                Value = "Basic",
                XPathList = new List<XmlXPath> { 
                    new XmlXPath { XPath = "/configuration/system.serviceModel/services/service/@behaviorConfiguration", UseTagItemValue = false },
                    new XmlXPath { XPath = "/configuration/system.serviceModel/services/service/endpoint/@bindingConfiguration", UseTagItemValue = false },
                    new XmlXPath { XPath = "/configuration/system.serviceModel/services/service/endpoint/@binding", UseTagItemValue = true },
                    new XmlXPath { XPath = "/configuration/applicationConfiguration/servicesConfiguration/@criptographyLevel", UseTagItemValue = false},
                    new XmlXPath { XPath = "/configuration/system.serviceModel/client/endpoint/@binding", UseTagItemValue = true }
                }
            });

            //xmlFile.Tags.Add(new XmlTag()
            //{
            //    Description = "Porta do servidor do Gerenciador de Processos",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.EndpointPort,
            //    Value = "62005",
            //    IsVisible = false,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath ="/configuration/applicationConfiguration/inteligenceManagerConfiguration/@inteligenceManagerAddress" }
            //});

            xmlFile.Tags.Add(new XmlTag()
            {
                Description = "Timeout da Aplicação (minutos)",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                Value = "30",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/applicationConfiguration/servicesConfiguration/@channelTimeout" } }
            });

            xmlFile.Tags.Add(new XmlTag()
            {
                Description = "Email",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                Value = "suportesinacor@bvmf.com.br",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/applicationConfiguration/logPackagerConfiguration/@supportEmail" } }
            });

            xmlFile.Tags.Add(new XmlTag()
            {
                Description = "Enviar erros da estação para o servidor",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Boolean,
                Value = "true",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/applicationConfiguration/errorLoggingConfiguration/@keepClientErrors" } }
            });

            c.XmlFiles.Add(xmlFile);

            c.XmlFiles.Add(CreateLocalEndPoint(group, "BM&F", "BMF"));
            c.XmlFiles.Add(CreateLocalEndPoint(group, "Bovespa", "Bovespa"));
            c.XmlFiles.Add(CreateLocalEndPoint(group, "Clientes", "Clientes"));
            c.XmlFiles.Add(CreateLocalEndPoint(group, "Conta Corrente", "ContaCorrente"));
            c.XmlFiles.Add(CreateLocalEndPoint(group, "Informação de Apoio", "InformacaoApoio"));
            c.XmlFiles.Add(CreateLocalEndPoint(group, "Infra Services", "Infra"));
            c.XmlFiles.Add(CreateLocalEndPoint(group, "Solicitações", "Solicitacoes"));
            c.XmlFiles.Add(CreateLocalEndPoint(group, "Tesouraria", "Tesouraria"));
            c.XmlFiles.Add(CreateLocalEndPoint(group, "Contas a Pagar", "ContasPagar"));

            group.Actions.Add(c);
        }

        private static XmlFile CreateLocalEndPoint(Group group, string moduleName, string folder)
        {
            XmlFile xmlFile = new XmlFile()
            {
                Description = "Configuração do endereço dos serviços do módulo " + moduleName,
                Title = "Servidor de " + moduleName,
                Folder = new FolderInfo()
                {
                    Source = @"Bin\Sinacor\Settings\Endpoints\" + folder,
                    Destination = @"Sinacor\Settings\Endpoints\" + folder,
                }
            };

            xmlFile.Tags.Add(new XmlTag()
            {
                Description = "Servidor",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Endpoint,
                Value = "localhost",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/system.serviceModel/client/endpoint/@address" } }
            });

            //xmlFile.Tags.Add(new XmlTag()
            //{
            //    Description = "Porta",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.EndpointPort,
            //    Value = "808",
            //    IsVisible = false,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath ="/configuration/system.serviceModel/client/endpoint/@address" }
            //});

            return xmlFile;
        }

        private static void AddActionUpdateConfigInterfaceLayer(Group group)
        {
            UpdateConfig c = new UpdateConfig();
            c.Id = "UpdateConfig-" + group.Id;
            c.Description = "Atualizaçao de config";
            c.GroupId = group.Id;
            c.Index = 15;

            c.XmlFiles = new List<XmlFile>();

            #region Sinacor.exe.config

            XmlFile sinacorExeConfigFile = new XmlFile();
            sinacorExeConfigFile.Description = "Configuração da Aplicação";
            sinacorExeConfigFile.Title = "Aplicação";
            sinacorExeConfigFile.Folder = new FolderInfo();
            sinacorExeConfigFile.Folder.Source = @"Bin\" + group.System.Id + @"\" + @"UI\Application\";
            sinacorExeConfigFile.Folder.Destination = group.System.Id + @"\" + @"UI\Application\";
            sinacorExeConfigFile.Folder.Files = new List<string>();
            sinacorExeConfigFile.Folder.Files.Add("Sinacor.exe.config");

            //sinacorExeAppConfigFile.Tags.Add(new XmlTag()
            //{
            //    Description = "TimeOut da Aplicação",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
            //    Value = "15",
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='ApplicationTimeOut']/@value" } }
            //});

            sinacorExeConfigFile.Tags.Add(new XmlTag()
            {
                Description = "Número máximo de favoritos",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                Value = "5",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='FavoriteMaxNumber']/@value" } }
            });

            sinacorExeConfigFile.Tags.Add(new XmlTag()
            {
                Description = "Número máximo de favoritos por empresa",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                Value = "5",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='CompanyFavoriteMaxNumber']/@value" } }
            });

            c.XmlFiles.Add(sinacorExeConfigFile);

            #endregion

            #region Relatorios

            XmlFile centuraReport = new XmlFile();
            centuraReport.Description = "Caminho dos executáveis do Sinacor Centura";
            centuraReport.Title = "Relatórios";
            centuraReport.Folder = new FolderInfo();
            centuraReport.Folder.Source = @"Bin\" + group.System.Id + @"\" + @"UI\Application\";
            centuraReport.Folder.Destination = group.System.Id + @"\" + @"UI\Application\";
            centuraReport.Folder.Files = new List<string>();
            centuraReport.Folder.Files.Add("Sinacor.exe.config");

            centuraReport.Tags.Add(new XmlTag()
            {
                Description = "Cadastro de Clientes",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/modules/installedModules/module[@name='CLI']/@centuraPath" } },
                IsRequired = false
            });
            centuraReport.Tags.Add(new XmlTag()
            {
                Description = "Contas à Pagar",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/modules/installedModules/module[@name='CTP']/@centuraPath" } },
                IsRequired = false
            });
            centuraReport.Tags.Add(new XmlTag()
            {
                Description = "Contas Correntes",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/modules/installedModules/module[@name='CCO']/@centuraPath" } },
                IsRequired = false
            });
            centuraReport.Tags.Add(new XmlTag()
            {
                Description = "Controle de Ordens BM&F",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/modules/installedModules/module[@name='OMF']/@centuraPath" } },
                IsRequired = false
            });
            centuraReport.Tags.Add(new XmlTag()
            {
                Description = "Controle de Ordens Bovespa",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/modules/installedModules/module[@name='ORD']/@centuraPath" } },
                IsRequired = false
            });
            centuraReport.Tags.Add(new XmlTag()
            {
                Description = "Faturamento BM&F",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/modules/installedModules/module[@name='BMF']/@centuraPath" } },
                IsRequired = false
            });
            centuraReport.Tags.Add(new XmlTag()
            {
                Description = "Faturamento Bovespa",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/modules/installedModules/module[@name='BOL']/@centuraPath" } },
                IsRequired = false
            });
            //centuraReport.Tags.Add(new XmlTag()
            //{
            //    Description = "Informações de Apoio",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/modules/installedModules/module[@name='TGE']/@centuraPath" } },
            //    IsRequired = false
            //});
            centuraReport.Tags.Add(new XmlTag()
            {
                Description = "Solicitações",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/modules/installedModules/module[@name='SOL']/@centuraPath" } },
                IsRequired = false
            });
            centuraReport.Tags.Add(new XmlTag()
            {
                Description = "Tesouraria",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/modules/installedModules/module[@name='TES']/@centuraPath" } },
                IsRequired = false
            });

            c.XmlFiles.Add(centuraReport);

            #endregion

            group.Actions.Add(c);
        }

        private static void AddActionUpdateConfigProcessManager(Group group, string moduleName, params string[] folders)
        {
            UpdateConfig c = new UpdateConfig();
            c.Id = "UpdateConfig-" + group.Id;
            c.Description = "Atualizaçao de config";
            c.GroupId = group.Id;
            c.Index = 15;

            foreach (string folder in folders)
            {
                XmlFile xmlFile = new XmlFile()
                {
                    Description = "Configuração dos processos do módulo " + moduleName,
                    Title = "Processos",
                    Folder = new FolderInfo()
                    {
                        Source = @"Bin\" + group.System.Id + @"\" + @"Processos\" + folder,
                        Destination = group.System.Id + @"\" + @"Processos\" + folder,
                    }
                };

                #region processConfiguration
                xmlFile.Tags.Add(new XmlTag()
                {
                    Description = "Ativo",
                    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Boolean,
                    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/@enabled" } },
                    Value = "False"
                });

                xmlFile.Tags.Add(new XmlTag()
                {
                    Description = "Nome do usuário do Sinacor",
                    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@loginName" } }
                });

                xmlFile.Tags.Add(new XmlTag()
                {
                    Description = "Senha do usuário do Sinacor",
                    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
                    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@password" } },
                    IsEncrypted = true,
                    EncryptionAlgorithm = CryptographyAlgorithm.RSA_Infra,
                    AlgorithmPublicKey = Sinacor.Infra.Common.Security.Cryptography.RSACryptographer.PublicKey
                });

                xmlFile.Tags.Add(new XmlTag()
                {
                    Description = "Empresa do Sinacor",
                    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                    IsList = true,
                    SQLCommand = "SELECT * FROM TGEEMPR",
                    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@companyId" } }
                });
                #endregion

                c.XmlFiles = new List<XmlFile>();
                c.XmlFiles.Add(xmlFile);
            }

            group.Actions.Add(c);
        }

        private static void AddActionUpdateConfigProcessManagerOrdensBMF(Group group, string moduleName, string folder)
        {
            UpdateConfig c = new UpdateConfig();
            c.Id = "UpdateConfig-" + group.Id;
            c.Description = "Atualizaçao de config";
            c.GroupId = group.Id;
            c.Index = 15;

            //#region Generic

            //XmlFile xmlFile = new XmlFile()
            //{
            //    Description = "Configuração dos processos do módulo " + moduleName,
            //    Title = "Processos",
            //    Folder = new FolderInfo()
            //    {
            //        Source = @"Bin\" + group.System.Id + @"\" + @"Processos\" + folder,
            //        Destination = group.System.Id + @"\" + @"Processos\" + folder,
            //    }
            //};

            //#region processConfiguration
            //xmlFile.Tags.Add(new XmlTag()
            //{
            //    Description = "Ativo",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Boolean,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/@enabled" } }
            //});

            //xmlFile.Tags.Add(new XmlTag()
            //{
            //    Description = "Nome do usuário do Sinacor",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@loginName" } }
            //});

            //xmlFile.Tags.Add(new XmlTag()
            //{
            //    Description = "Senha do usuário do Sinacor",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@password" } },
            //    IsEncrypted = true,
            //    EncryptionAlgorithm = CryptographyAlgorithm.RSA_Infra,
            //    AlgorithmPublicKey = Sinacor.Infra.Common.Security.Cryptography.RSACryptographer.PublicKey
            //});

            //xmlFile.Tags.Add(new XmlTag()
            //{
            //    Description = "Empresa do Sinacor",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
            //    IsList = true,
            //    SQLCommand = "SELECT * FROM TGEEMPR",
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@companyId" } }
            //});
            //#endregion

            //#endregion

            #region Automacao

            XmlFile xmlFileAutomacao = new XmlFile()
            {
                Description = "Configuração do processo do Automação de Ordens",
                Title = "Processo de Automação de Ordens",
                Folder = new FolderInfo()
                {
                    Source = @"Bin\" + group.System.Id + @"\" + @"Processos\" + folder + @"\AutomacaoOrdens",
                    Destination = group.System.Id + @"\" + @"Processos\" + folder + @"\AutomacaoOrdens",
                    Files = new List<string>() { "Sinacor.Process.Bmf.AutomacaoOrdens.Server.dll.config" }
                }
            };

            #region appSettings

            xmlFileAutomacao.Tags.Add(new XmlTag()
            {
                Description = "Quantidade Solicitada",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                Value = "300",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='quantidadeSolicidata']/@value" } }
            });

            xmlFileAutomacao.Tags.Add(new XmlTag()
            {
                Description = "Intervalo da Solicitacao",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                Value = "15000",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='intervaloSolicitacao']/@value" } }
            });

            xmlFileAutomacao.Tags.Add(new XmlTag()
            {
                Description = "Código da Corretora na BM&F",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='codigoCorretoraBmf']/@value" } }
            });

            #endregion

            //#region processConfiguration
            //xmlFileAutomacao.Tags.Add(new XmlTag()
            //{
            //    Description = "Ativo",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Boolean,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/@enabled" } }
            //});

            //xmlFileAutomacao.Tags.Add(new XmlTag()
            //{
            //    Description = "Nome do usuário do Sinacor",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@loginName" } }
            //});

            //xmlFileAutomacao.Tags.Add(new XmlTag()
            //{
            //    Description = "Senha do usuário do Sinacor",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@password" } },
            //    IsEncrypted = true,
            //    EncryptionAlgorithm = CryptographyAlgorithm.RSA_Infra,
            //    AlgorithmPublicKey = Sinacor.Infra.Common.Security.Cryptography.RSACryptographer.PublicKey,
            //});

            //xmlFileAutomacao.Tags.Add(new XmlTag()
            //{
            //    Description = "Empresa do Sinacor",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
            //    IsList = true,
            //    SQLCommand = "SELECT * FROM TGEEMPR",
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@companyId" } }
            //});
            //#endregion

            #endregion

            #region Liberacao

            XmlFile xmlFileLiberacao = new XmlFile()
            {
                Description = "Configuração do processo do Liberação Intenção",
                Title = "Processo de Liberação de Intenção",
                Folder = new FolderInfo()
                {
                    Source = @"Bin\" + group.System.Id + @"\" + @"Processos\" + folder + @"\LiberacaoIntencao",
                    Destination = group.System.Id + @"\" + @"Processos\" + folder + @"\LiberacaoIntencao",
                    Files = new List<string>() { "Sinacor.Process.Bmf.Liberacao.Server.dll.config" }
                }
            };

            #region appSettings

            xmlFileLiberacao.Tags.Add(new XmlTag()
            {
                Description = "Simulação",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Boolean,
                Value = "true",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='simulacao']/@value" } }
            });

            xmlFileLiberacao.Tags.Add(new XmlTag()
            {
                Description = "Código da Corretora na BM&F",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='codigoCorretoraBmf']/@value" } }
            });

            #endregion

            //#region processConfiguration
            //xmlFileLiberacao.Tags.Add(new XmlTag()
            //{
            //    Description = "Ativo",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Boolean,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/@enabled" } }
            //});

            //xmlFileLiberacao.Tags.Add(new XmlTag()
            //{
            //    Description = "Nome do usuário do Sinacor",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@loginName" } }
            //});

            //xmlFileLiberacao.Tags.Add(new XmlTag()
            //{
            //    Description = "Senha do usuário do Sinacor",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@password" } },
            //    IsEncrypted = true,
            //    EncryptionAlgorithm = CryptographyAlgorithm.RSA_Infra,
            //    AlgorithmPublicKey = Sinacor.Infra.Common.Security.Cryptography.RSACryptographer.PublicKey
            //});

            //xmlFileLiberacao.Tags.Add(new XmlTag()
            //{
            //    Description = "Empresa do Sinacor",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
            //    IsList = true,
            //    SQLCommand = "SELECT * FROM TGEEMPR",
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@companyId" } }
            //});
            //#endregion

            #region proxyCredentials
            xmlFileLiberacao.Tags.Add(new XmlTag()
            {
                Description = "Dominio de Autenticação do Proxy",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/xmlHttpOutputConfiguration/proxyCredentials/@domain" } },
                IsRequired = false
            });
            xmlFileLiberacao.Tags.Add(new XmlTag()
            {
                Description = "Usuário de Autenticação do Proxy",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/xmlHttpOutputConfiguration/proxyCredentials/@userName" } },
                IsRequired = false
            });
            xmlFileLiberacao.Tags.Add(new XmlTag()
            {
                Description = "Senha de Autenticação do Proxy",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/xmlHttpOutputConfiguration/proxyCredentials/@password" } },
                IsRequired = false,
                IsEncrypted = true,
                EncryptionAlgorithm = PSE.Deployment.SetupBase.Configuration.Enums.CryptographyAlgorithm.DES_Generic
            });
            #endregion

            #region credentials
            xmlFileLiberacao.Tags.Add(new XmlTag()
            {
                Description = "Dominio de Autenticação",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/xmlHttpOutputConfiguration/credentials/@domain" } },
                IsRequired = false
            });
            xmlFileLiberacao.Tags.Add(new XmlTag()
            {
                Description = "Usuário de Autenticação",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/xmlHttpOutputConfiguration/credentials/@userName" } },
                IsRequired = false
            });
            xmlFileLiberacao.Tags.Add(new XmlTag()
            {
                Description = "Senha de Autenticação",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/xmlHttpOutputConfiguration/credentials/@password" } },
                IsRequired = false,
                IsEncrypted = true,
                EncryptionAlgorithm = PSE.Deployment.SetupBase.Configuration.Enums.CryptographyAlgorithm.DES_Generic
            });
            #endregion

            #region session
            xmlFileLiberacao.Tags.Add(
            new XmlTag()
            {
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/fixConfiguration/fixmlSessions" } },
                Name = "session",
                Description = "Sessoes de Fixml",
                OperationType = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagOperationType.Insert,
                Attributes = new List<XmlAttribute>()
				{
					new XmlAttribute()
					{
						Name = "name",
						Description = "Nome da sessão",
						Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String
					},
					new XmlAttribute()
					{
						Name = "user",
						Description = "Nome do usuário",
						Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String
					},
					new XmlAttribute()
					{
						Name = "password",
						Description = "Senha do usuário",
						Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
						IsEncrypted = true,
						EncryptionAlgorithm = PSE.Deployment.SetupBase.Configuration.Enums.CryptographyAlgorithm.DES_Generic
					}
				}
            });
            #endregion

            #region xmlHttpOutputConfiguration
            xmlFileLiberacao.Tags.Add(
                new XmlTag()
                {
                    Description = "Url do Fixml",
                    OperationType = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagOperationType.Update,
                    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Uri,
                    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/xmlHttpOutputConfiguration/@url" } }
                }
                );
            #endregion

            #endregion

            c.XmlFiles = new List<XmlFile>();
            //c.XmlFiles.Add(xmlFile);
            c.XmlFiles.Add(xmlFileAutomacao);
            c.XmlFiles.Add(xmlFileLiberacao);

            group.Actions.Add(c);
        }

        private static void AddActionUpdateConfigProcessManagerBovespa(Group group, string moduleName, string folder)
        {
            UpdateConfig c = new UpdateConfig();
            c.Id = "UpdateConfig-" + group.Id;
            c.Description = "Atualizaçao de config";
            c.GroupId = group.Id;
            c.Index = 15;

            #region Generic

            XmlFile xmlFile = new XmlFile()
            {
                Description = "Configuração dos processos do módulo " + moduleName,
                Title = "Processos",
                Folder = new FolderInfo()
                {
                    Source = @"Bin\" + group.System.Id + @"\" + @"Processos\" + folder,
                    Destination = group.System.Id + @"\" + @"Processos\" + folder,
                }
            };

            #endregion

            #region Alocacao

            XmlFile xmlFileAlocacao = new XmlFile()
            {
                Description = "Configuração do processo do alocação",
                Title = "Processo de Alocação",
                Folder = new FolderInfo()
                {
                    Source = @"Bin\" + group.System.Id + @"\" + @"Processos\" + folder + @"\Alocacao",
                    Destination = group.System.Id + @"\" + @"Processos\" + folder + @"\Alocacao",
                    Files = new List<string>() { "Sinacor.Process.Bovespa.Alocacao.Server.dll.config" }
                }
            };

            #region appSettings

            xmlFileAlocacao.Tags.Add(new XmlTag()
            {
                Description = "Quantidade de registros por alocação",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                Value = "30000",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='QuantidadeRegistrosAlocacao']/@value" } }
            });

            #endregion

            #endregion

            c.XmlFiles = new List<XmlFile>();
            c.XmlFiles.Add(xmlFile);
            c.XmlFiles.Add(xmlFileAlocacao);

            group.Actions.Add(c);
        }

        private static void AddActionUpdateConfigProcessManagerClientes(Group group, string moduleName, string folder)
        {
            UpdateConfig c = new UpdateConfig();
            c.Id = "UpdateConfig-" + group.Id;
            c.Description = "Atualizaçao de config";
            c.GroupId = group.Id;
            c.Index = 15;

            //#region Generic

            //XmlFile xmlFile = new XmlFile()
            //{
            //    Description = "Configuração dos processos do módulo " + moduleName,
            //    Title = "Processos",
            //    Folder = new FolderInfo()
            //    {
            //        Source = @"Bin\" + group.System.Id + @"\" + @"Processos\" + folder,
            //        Destination = group.System.Id + @"\" + @"Processos\" + folder,
            //    }
            //};

            //#region processConfiguration
            //xmlFile.Tags.Add(new XmlTag()
            //{
            //    Description = "Ativo",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Boolean,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/@enabled" } }
            //});

            //xmlFile.Tags.Add(new XmlTag()
            //{
            //    Description = "Nome do usuário do Sinacor",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@loginName" } }
            //});

            //xmlFile.Tags.Add(new XmlTag()
            //{
            //    Description = "Senha do usuário do Sinacor",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@password" } },
            //    IsEncrypted = true,
            //    EncryptionAlgorithm = CryptographyAlgorithm.RSA_Infra,
            //    AlgorithmPublicKey = Sinacor.Infra.Common.Security.Cryptography.RSACryptographer.PublicKey
            //});

            //xmlFile.Tags.Add(new XmlTag()
            //{
            //    Description = "Empresa do Sinacor",
            //    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
            //    IsList = true,
            //    SQLCommand = "SELECT * FROM TGEEMPR",
            //    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@companyId" } }
            //});
            //#endregion

            //#endregion

            #region InativacaoContas

            XmlFile xmlFileInativacaoContas = new XmlFile()
            {
                Description = "Configuração do processo de Inativação de Contas",
                Title = "Inativação de Contas",
                Folder = new FolderInfo()
                {
                    Source = @"Bin\" + group.System.Id + @"\" + @"Processos\" + folder + @"\InativacaoContas",
                    Destination = group.System.Id + @"\" + @"Processos\" + folder + @"\InativacaoContas",
                    Files = new List<string>() { "Sinacor.Process.Clientes.InativacaoContas.Server.dll.config" }
                }
            };

            #region appSettings

            xmlFileInativacaoContas.Tags.Add(new XmlTag()
            {
                Description = "Qtde. de contas por processo (processamento paralelo)",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                Value = "10000",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='ContasPorProcesso']/@value" } }
            });

            xmlFileInativacaoContas.Tags.Add(new XmlTag()
            {
                Description = "Qtde. de registros a serem persistidos por ciclo de processamento para contas em BM&F",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                Value = "1000",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='QtdeRegistroCommitBMF']/@value" } }
            });

            xmlFileInativacaoContas.Tags.Add(new XmlTag()
            {
                Description = "Qtde. de registros a serem persistidos por ciclo de processamento para contas em Bovespa",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                Value = "1000",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='QtdeRegistroCommitBOL']/@value" } }
            });

            xmlFileInativacaoContas.Tags.Add(new XmlTag()
            {
                Description = "Qtde. de registros a serem persistidos por cliclo de proces. para contas no Cadastro Básico",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                Value = "1000",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='QtdeRegistroCommitCAD']/@value" } }
            });

            #endregion

            #endregion

            #region ContaExportacao

            XmlFile xmlContaExportacao = new XmlFile()
            {
                Description = "Configuração do processo de exportação de contas BM&F",
                Title = "Exportação de Contas BM&F",
                Folder = new FolderInfo()
                {
                    Source = @"Bin\" + group.System.Id + @"\" + @"Processos\" + folder + @"\ContaCliExpXML",
                    Destination = group.System.Id + @"\" + @"Processos\" + folder + @"\ContaCliExpXML",
                    Files = new List<string>() { "Sinacor.Process.Clientes.ContaCliExpXML.Server.dll.config" }
                }
            };

            #region processConfiguration
            xmlContaExportacao.Tags.Add(new XmlTag()
            {
                Description = "Ativo",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Boolean,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/@enabled" } },
                Value = "False"
            });

            xmlContaExportacao.Tags.Add(new XmlTag()
            {
                Description = "Nome do usuário do Sinacor",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@loginName" } }
            });

            xmlContaExportacao.Tags.Add(new XmlTag()
            {
                Description = "Senha do usuário do Sinacor",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@password" } },
                IsEncrypted = true,
                EncryptionAlgorithm = CryptographyAlgorithm.RSA_Infra,
                AlgorithmPublicKey = Sinacor.Infra.Common.Security.Cryptography.RSACryptographer.PublicKey
            });

            xmlContaExportacao.Tags.Add(new XmlTag()
            {
                Description = "Empresa do Sinacor",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                IsList = true,
                SQLCommand = "SELECT * FROM TGEEMPR",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@companyId" } }
            });
            #endregion

            #region appSettings

            xmlContaExportacao.Tags.Add(new XmlTag()
            {
                Description = "Usuário",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='userName']/@value" } }
            });

            xmlContaExportacao.Tags.Add(new XmlTag()
            {
                Description = "Senha",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
                IsEncrypted = true,
                EncryptionAlgorithm = CryptographyAlgorithm.DES_Generic,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='password']/@value" } }
            });

            xmlContaExportacao.Tags.Add(new XmlTag()
            {
                Description = "Url",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Uri,
                Value = "http://intranet2d.bmf.com.br/CPLServices/WsCPLMessageBroker.asmx",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='UrlCPLWebService']/@value" } }
            });

            xmlContaExportacao.Tags.Add(new XmlTag()
            {
                Description = "Intervalo do ciclo de verificação do processo",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                Value = "120000",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='IntervaloGerenciador']/@value" } }
            });

            xmlContaExportacao.Tags.Add(new XmlTag()
            {
                Description = "Dominio de Autenticação do Proxy",
                IsRequired = false,
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='domainProxy']/@value" } }
            });

            xmlContaExportacao.Tags.Add(new XmlTag()
            {
                Description = "Usuário de Autenticação do Proxy",
                IsRequired = false,
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='userNameProxy']/@value" } }
            });

            xmlContaExportacao.Tags.Add(new XmlTag()
            {
                Description = "Senha de Autenticação do Proxy",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
                IsRequired = false,
                EncryptionAlgorithm = CryptographyAlgorithm.DES_Generic,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='passwordProxy']/@value" } }
            });

            #endregion

            #endregion

            #region MTA

            XmlFile xmlFileMTA = new XmlFile()
            {
                Description = "Configuração dos diretórios de importação e exportação",
                Title = "Diretórios do MTA",
                Folder = new FolderInfo()
                {
                    Source = @"Bin\" + group.System.Id + @"\" + @"Processos\Clientes\",
                    Destination = group.System.Id + @"\" + @"Processos\Clientes\",
                }
            };

            xmlFileMTA.Tags.Add(new XmlTag()
            {
                Description = "Pasta dos arquivos a serem enviados pelo MTA",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                Value = @"C:\ExportacaoSinacor",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='PastaPadrao']/@value" } }
            });

            xmlFileMTA.Tags.Add(new XmlTag()
            {
                Description = "Pasta dos arquivos a serem recebidos pelo MTA",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                Value = @"C:\ImportacaoSinacor",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='CaminhoImportacaoAutomatica']/@value" } }
            });

            #endregion

            c.XmlFiles = new List<XmlFile>();
            //c.XmlFiles.Add(xmlFile);
            c.XmlFiles.Add(xmlFileInativacaoContas);
            c.XmlFiles.Add(xmlContaExportacao);
            c.XmlFiles.Add(xmlFileMTA);

            group.Actions.Add(c);
        }

        private static void AddActionUpdateConfigProcessManagerTesouraria(Group group, string moduleName, params string[] folders)
        {
            UpdateConfig c = new UpdateConfig();
            c.Id = "UpdateConfig-" + group.Id;
            c.Description = "Atualizaçao de config";
            c.GroupId = group.Id;
            c.Index = 15;
            c.XmlFiles = new List<XmlFile>();

            #region Generic

            foreach (string folder in folders)
            {
                XmlFile xmlFile = new XmlFile()
                {
                    Description = "Configuração dos processos do módulo " + folder,
                    Title = "Processos de " + folder,
                    Folder = new FolderInfo()
                    {
                        Source = @"Bin\" + group.System.Id + @"\" + @"Processos\" + folder,
                        Destination = group.System.Id + @"\" + @"Processos\" + folder,
                    }
                };

                xmlFile.Tags.Add(new XmlTag()
                {
                    Description = "Ativo",
                    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Boolean,
                    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/@enabled" } },
                    Value = "False"
                });

                xmlFile.Tags.Add(new XmlTag()
                {
                    Description = "Nome do usuário do Sinacor",
                    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@loginName" } }
                });

                xmlFile.Tags.Add(new XmlTag()
                {
                    Description = "Senha do usuário do Sinacor",
                    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
                    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@password" } },
                    IsEncrypted = true,
                    EncryptionAlgorithm = CryptographyAlgorithm.RSA_Infra,
                    AlgorithmPublicKey = Sinacor.Infra.Common.Security.Cryptography.RSACryptographer.PublicKey
                });

                xmlFile.Tags.Add(new XmlTag()
                {
                    Description = "Empresa do Sinacor",
                    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                    IsList = true,
                    SQLCommand = "SELECT * FROM TGEEMPR",
                    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@companyId" } }
                });

                c.XmlFiles.Add(xmlFile);
            }

            #endregion

            #region SPBX

            XmlFile xmlFileSPBX = new XmlFile()
            {
                Description = "Configuração do processo do SPBx",
                Title = "Processo de SPBx",
                Folder = new FolderInfo()
                {
                    Source = @"Bin\" + group.System.Id + @"\" + @"Processos\Tesouraria\SPBx",
                    Destination = group.System.Id + @"\" + @"Processos\Tesouraria\SPBx",
                    Files = new List<string>() { "Sinacor.Process.Tesouraria.SPBx.Server.dll.config" }
                }
            };

            #region processConfiguration
            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Ativo",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Boolean,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/@enabled" } },
                Value = "False"
            });

            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Nome do usuário do Sinacor",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@loginName" } }
            });

            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Senha do usuário do Sinacor",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@password" } },
                IsEncrypted = true,
                EncryptionAlgorithm = CryptographyAlgorithm.RSA_Infra,
                AlgorithmPublicKey = Sinacor.Infra.Common.Security.Cryptography.RSACryptographer.PublicKey
            });

            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Empresa do Sinacor",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                IsList = true,
                SQLCommand = "SELECT * FROM TGEEMPR",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@companyId" } }
            });
            #endregion

            #region appSettings

            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Process Time Elapsed",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                IsVisible = false,
                Value = "10000",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='ProcessTimeElapsed']/@value" } }
            });
            //<XmlTag Description="Process Time Elapsed" Value="10000" HasChanges="false" XPath="/configuration/appSettings/add[@key='ProcessTimeElapsed']/@value" Type="Integer" OperationType="Update" IsList="false" IsVisible="true" IsEncrypted="false" EncryptionAlgorithm="DES_Generic" IsRequired="true">

            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Process Time Elapsed Saldo",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                IsVisible = false,
                Value = "3600000",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='ProcessTimeElapsedSaldo']/@value" } }
            });
            //<XmlTag Description="Process Time Elapsed Saldo" Value="3600000" HasChanges="false" XPath="/configuration/appSettings/add[@key='ProcessTimeElapsedSaldo']/@value" Type="Integer" OperationType="Update" IsList="false" IsVisible="true" IsEncrypted="false" EncryptionAlgorithm="DES_Generic" IsRequired="true">

            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Identificador Emissor ISPB",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='IdentificadorEmissorISPB']/@value" } }
            });
            //<XmlTag Description="Identificador Emissor ISPB" Value="61787776" HasChanges="false" XPath="/configuration/appSettings/add[@key='IdentificadorEmissorISPB']/@value" Type="Integer" OperationType="Update" IsList="false" IsVisible="true" IsEncrypted="false" EncryptionAlgorithm="DES_Generic" IsRequired="true">

            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Identificador Destinatario ISPB",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='IdentificadorDestinatarioISPB']/@value" } }
            });
            //<XmlTag Description="Identificador Destinatario ISPB" Value="00038166" HasChanges="false" XPath="/configuration/appSettings/add[@key='IdentificadorDestinatarioISPB']/@value" Type="String" OperationType="Update" IsList="false" IsVisible="true" IsEncrypted="false" EncryptionAlgorithm="DES_Generic" IsRequired="true">

            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Session Name",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                Value = "SPB",
                IsVisible = false,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/spbConfiguration/spbSessions/session/@name" } }
            });
            //<XmlTag Description="Session Name" Value="SPB" HasChanges="false" XPath="/configuration/spbConfiguration/spbSessions/session/@name" Type="String" OperationType="Update" IsList="false" IsVisible="true" IsEncrypted="false" EncryptionAlgorithm="DES_Generic" IsRequired="true">

            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Nome do usuário do SPBx",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/spbConfiguration/spbSessions/session/@user" } }
            });
            //<XmlTag Description="Session User" Value="" HasChanges="false" XPath="/configuration/spbConfiguration/spbSessions/session/@user" Type="String" OperationType="Update" IsList="false" IsVisible="true" IsEncrypted="false" EncryptionAlgorithm="DES_Generic" IsRequired="true">

            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Senha do usuário do SPBx",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/spbConfiguration/spbSessions/session/@password" } },
                IsEncrypted = true,
            });
            //<XmlTag Description="Session Password" HasChanges="false" XPath="/configuration/spbConfiguration/spbSessions/session/@password" Type="Password" OperationType="Update" IsList="false" IsVisible="true" IsEncrypted="true" EncryptionAlgorithm="DES_Generic" IsRequired="true">

            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Endereço do servidor do SPBx",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/spbConfiguration/spbSessions/session/@host" } }
            });
            //<XmlTag Description="Session Host" Value="" HasChanges="false" XPath="/configuration/spbConfiguration/spbSessions/session/@host" Type="String" OperationType="Update" IsList="false" IsVisible="true" IsEncrypted="false" EncryptionAlgorithm="DES_Generic" IsRequired="true">

            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Porta do servidor do SPBx",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/spbConfiguration/spbSessions/session/@porta" } }
            });
            //<XmlTag Description="Host Port" Value="" HasChanges="false" XPath="/configuration/spbConfiguration/spbSessions/session/@porta" Type="Integer" OperationType="Update" IsList="false" IsVisible="true" IsEncrypted="false" EncryptionAlgorithm="DES_Generic" IsRequired="true">

            xmlFileSPBX.Tags.Add(new XmlTag()
            {
                Description = "Heart Beat",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Integer,
                Value = "30000",
                IsVisible = false,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/spbConfiguration/spbSessions/session/@heartBeat" } }
            });
            //<XmlTag Description="Heart Beat" Value="30000" HasChanges="false" XPath="/configuration/spbConfiguration/spbSessions/session/@heartBeat" Type="Integer" OperationType="Update" IsList="false" IsVisible="true" IsEncrypted="false" EncryptionAlgorithm="DES_Generic" IsRequired="true">

            #endregion

            c.XmlFiles.Add(xmlFileSPBX);

            #endregion

            #region MonitorImportacao

            XmlFile xmlFileMonitorImportacao = new XmlFile()
            {
                Description = "Configuração do processo de Monitor de Importação",
                Title = "Monitor de Importação",
                Folder = new FolderInfo()
                {
                    Source = @"Bin\" + group.System.Id + @"\" + @"Processos\Solicitacoes\MonitorImportacao",
                    Destination = group.System.Id + @"\" + @"Processos\Solicitacoes\MonitorImportacao",
                    Files = new List<string>() { "Sinacor.Process.Solicitacoes.MonitorImportacao.Server.dll.config" }
                }
            };

            #region processConfiguration
            xmlFileMonitorImportacao.Tags.Add(new XmlTag()
            {
                Description = "Ativo",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Boolean,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/@enabled" } },
                Value = "False"
            });

            xmlFileMonitorImportacao.Tags.Add(new XmlTag()
            {
                Description = "Nome do usuário do Sinacor",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@loginName" } }
            });

            xmlFileMonitorImportacao.Tags.Add(new XmlTag()
            {
                Description = "Senha do usuário do Sinacor",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@password" } },
                IsEncrypted = true,
                EncryptionAlgorithm = CryptographyAlgorithm.RSA_Infra,
                AlgorithmPublicKey = Sinacor.Infra.Common.Security.Cryptography.RSACryptographer.PublicKey
            });

            xmlFileMonitorImportacao.Tags.Add(new XmlTag()
            {
                Description = "Empresa do Sinacor",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                IsList = true,
                SQLCommand = "SELECT * FROM TGEEMPR",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/authenticationConfiguration/@companyId" } }
            });

            xmlFileMonitorImportacao.Tags.Add(new XmlTag()
            {
                Description = "Domínio Windows",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/identity/@domain" } },
                Value = ""
            });

            xmlFileMonitorImportacao.Tags.Add(new XmlTag()
            {
                Description = "Nome do usuário Windows",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.String,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/identity/@userName" } },
                Value = ""
            });

            xmlFileMonitorImportacao.Tags.Add(new XmlTag()
            {
                Description = "Senha do usuário Windows",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.Password,
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/processConfiguration/identity/@password" } },
                Value = "",
                IsEncrypted = false
                //EncryptionAlgorithm = CryptographyAlgorithm.RSA_Infra,
                //AlgorithmPublicKey = PSE.Framework.Common. Sinacor.Infra.Common.Security.Cryptography.RSACryptographer.PublicKey
            });
            #endregion

            c.XmlFiles.Add(xmlFileMonitorImportacao);

            #endregion

            #region MTA

            foreach (string folder in folders)
            {
                XmlFile xmlFileMTA = new XmlFile()
                {
                    Description = "Configuração dos diretórios de importação e exportação",
                    Title = "Diretórios do MTA de " + folder,
                    Folder = new FolderInfo()
                    {
                        Source = @"Bin\" + group.System.Id + @"\" + @"Processos\" + folder,
                        Destination = group.System.Id + @"\" + @"Processos\" + folder,
                    }
                };

                xmlFileMTA.Tags.Add(new XmlTag()
                {
                    Description = "Pasta dos arquivos a serem enviados pelo MTA",
                    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                    Value = @"C:\ExportacaoSinacor",
                    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='PastaPadrao']/@value" } }
                });

                xmlFileMTA.Tags.Add(new XmlTag()
                {
                    Description = "Pasta dos arquivos a serem recebidos pelo MTA",
                    Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                    Value = @"C:\ImportacaoSinacor",
                    XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='CaminhoImportacaoAutomatica']/@value" } }
                });

                c.XmlFiles.Add(xmlFileMTA);
            }

            #endregion

            group.Actions.Add(c);
        }

        private static void AddActionUpdateConfigProcessManagerGeneral(Group group)
        {
            UpdateConfig c = new UpdateConfig();
            c.Id = "UpdateConfig-" + group.Id;
            c.Description = "Atualizaçao de config";
            c.GroupId = group.Id;
            c.Index = 15;

            XmlFile xmlFile = new XmlFile()
            {
                Description = "Configurações gerais dos processos",
                Title = "Processos",
                Folder = new FolderInfo()
                {
                    Source = @"Bin\" + group.System.Id + @"\" + @"Processos\",
                    Destination = group.System.Id + @"\" + @"Processos\",
                }
            };

            xmlFile.Tags.Add(new XmlTag()
            {
                Description = "Pasta dos arquivos a serem enviados pelo MTA",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                Value = @"C:\ExportacaoSinacor",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='PastaPadrao']/@value" } }
            });

            xmlFile.Tags.Add(new XmlTag()
            {
                Description = "Pasta dos arquivos a serem recebidos pelo MTA",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                Value = @"C:\ImportacaoSinacor",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='CaminhoImportacaoAutomatica']/@value" } }
            });

            c.XmlFiles = new List<XmlFile>();
            c.XmlFiles.Add(xmlFile);

            group.Actions.Add(c);
        }

        private static void AddActionUpdateConfigProcessManagerBovespa(Group group)
        {
            UpdateConfig c = new UpdateConfig();
            c.Id = "UpdateConfig-" + group.Id;
            c.Description = "Atualizaçao de config";
            c.GroupId = group.Id;
            c.Index = 15;

            XmlFile xmlFile = new XmlFile()
            {
                Description = "Configuração dos diretórios de importação e exportação",
                Title = "Diretórios do MTA",
                Folder = new FolderInfo()
                {
                    Source = @"Bin\" + group.System.Id + @"\" + @"Processos\Bovespa\",
                    Destination = group.System.Id + @"\" + @"Processos\Bovespa\",
                }
            };

            xmlFile.Tags.Add(new XmlTag()
            {
                Description = "Pasta dos arquivos a serem enviados pelo MTA",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                Value = @"C:\ExportacaoSinacor",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='PastaPadrao']/@value" } }
            });

            xmlFile.Tags.Add(new XmlTag()
            {
                Description = "Pasta dos arquivos a serem recebidos pelo MTA",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                Value = @"C:\ImportacaoSinacor",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='CaminhoImportacaoAutomatica']/@value" } }
            });

            c.XmlFiles = new List<XmlFile>();
            c.XmlFiles.Add(xmlFile);

            group.Actions.Add(c);
        }

        private static void AddActionUpdateConfigProcessManagerBmf(Group group)
        {
            UpdateConfig c = new UpdateConfig();
            c.Id = "UpdateConfig-" + group.Id;
            c.Description = "Atualizaçao de config";
            c.GroupId = group.Id;
            c.Index = 15;

            XmlFile xmlFile = new XmlFile()
            {
                Description = "Configuração dos diretórios de importação e exportação",
                Title = "Diretórios do MTA",
                Folder = new FolderInfo()
                {
                    Source = @"Bin\" + group.System.Id + @"\" + @"Processos\Bmf\",
                    Destination = group.System.Id + @"\" + @"Processos\Bmf\",
                }
            };

            xmlFile.Tags.Add(new XmlTag()
            {
                Description = "Pasta dos arquivos a serem enviados pelo MTA",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                Value = @"C:\ExportacaoSinacor",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='PastaPadrao']/@value" } }
            });

            xmlFile.Tags.Add(new XmlTag()
            {
                Description = "Pasta dos arquivos a serem recebidos pelo MTA",
                Type = PSE.Deployment.SetupBase.Configuration.Enums.XmlTagType.FolderPath,
                Value = @"C:\ImportacaoSinacor",
                XPathList = new List<XmlXPath> { new XmlXPath { XPath = "/configuration/appSettings/add[@key='CaminhoImportacaoAutomatica']/@value" } }
            });

            c.XmlFiles = new List<XmlFile>();
            c.XmlFiles.Add(xmlFile);

            group.Actions.Add(c);
        }

        private static ProcessManagerInstance GetInstance(string instance_name)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("SELECT COD_ISTA, COD_PRDT, NOME_ISTA, DESC_URL_ISTA FROM TFWDISTA_GDOR_PROS_PRDT ");
            sql.Append("WHERE NOME_ISTA = :NOME_ISTA ");

            OracleConnection connection = new OracleConnection(_connectionString);
            OracleCommand command = connection.CreateCommand();
            command.CommandText = sql.ToString();
            command.CommandType = System.Data.CommandType.Text;
            command.Parameters.Add(new OracleParameter("NOME_ISTA", instance_name));

            try
            {
                connection.Open();

                using (IDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        ProcessManagerInstance instance = new ProcessManagerInstance();
                        instance.InstanceName = reader.GetString(2);
                        instance.InstanceAddress = reader.GetString(3);
                        instance.ProcessPath = @"Sinacor\Processos";
                        instance.ProductName = "Sinacor";
                        instance.ServiceCertificateName = "SinacorService";
                        instance.STSAuthorityCertificateName = "SinacorSTSAuthority";
                        instance.Processes = GetProcesses(reader.GetInt32(0));

                        return instance;
                    }
                    else
                        return null;
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                connection.Close();
            }

        }

        private static List<ProcessManagerProcess> GetProcesses(int cod_instance)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("SELECT ");
            sql.Append("PROCESSO.COD_PROS, PROCESSO.COD_ISTA, PROCESSO.COD_MOD_INTL, PROCESSO.NOME_PROS, ");
            sql.Append("PROCESSO.DESC_PROS, PROCESSO.COD_TIPO_CNTX_ISTA, PROCESSO.NOME_CLAS, ");
            sql.Append("PROCESSO.NOME_ASSBLY, PROCESSO.COD_ACAO_PRIM_FALH_PROS, PROCESSO.COD_ACAO_SEGD_FALH_PROS, ");
            sql.Append("PROCESSO.COD_ACAO_FALH_SUBQ_PROS, PROCESSO.COD_TIPO_INIC_PROS, PROCESSO.COD_PRDT, ");
            sql.Append("PRODUTO.NOME_PRDT, INSTANCIA.NOME_ISTA, INTMODULE.NOME_MOD_INTL ");
            sql.Append("FROM TFWDCNFG_GDOR_PROS PROCESSO ");
            sql.Append("INNER JOIN TFWDISTA_GDOR_PROS_PRDT INSTANCIA ");
            sql.Append("ON PROCESSO.COD_PRDT = INSTANCIA.COD_PRDT AND PROCESSO.COD_ISTA = INSTANCIA.COD_ISTA ");
            sql.Append("INNER JOIN TFWDMOD_INTL_GDOR_PROS INTMODULE ");
            sql.Append("ON PROCESSO.COD_MOD_INTL = INTMODULE.COD_MOD_INTL ");
            sql.Append("INNER JOIN TFWDPRDT_GDOR_PROS PRODUTO ");
            sql.Append("ON PROCESSO.COD_PRDT = PRODUTO.COD_PRDT ");
            sql.Append("WHERE PROCESSO.COD_ISTA = :COD_ISTA AND PROCESSO.IND_ATIV = 'S'");
            sql.Append("ORDER BY  PRODUTO.NOME_PRDT,PROCESSO.COD_PROS ");

            OracleConnection connection = new OracleConnection(_connectionString);
            OracleCommand command = connection.CreateCommand();
            command.CommandText = sql.ToString();
            command.CommandType = System.Data.CommandType.Text;
            command.Parameters.Add(new OracleParameter("COD_ISTA", cod_instance));

            List<ProcessManagerProcess> processes = new List<ProcessManagerProcess>();

            try
            {
                connection.Open();

                using (IDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        ProcessManagerProcess process = new ProcessManagerProcess();
                        process.Id = reader.GetInt32(0);
                        process.InteligenceModuleId = reader.GetInt32(2);
                        process.Name = reader.GetString(3);
                        process.Description = reader.GetString(4);
                        process.InstanceContext = reader.GetString(5);
                        process.Class = reader.GetString(6);
                        process.Assembly = reader.GetString(7);
                        process.FailureRecovery = reader.GetString(8);
                        process.InitializationType = reader.GetString(11);
                        processes.Add(process);
                    }
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                connection.Close();
            }

            return processes;
        }
    }
}
